/** * 发送评论 */ function send() { $this->response->addHeader('Content-Type', 'application/json'); if (!login::user()) { return json_encode(array('code' => 3, 'result' => '尚未登陆')); } $pid = filter::int($this->post->pid); $content = $this->post->content; if (isset($_FILES['file'])) { $image = new image(); $files = $this->file->receiveMultiFile($_FILES['file'], config('file')); foreach ($files as &$file) { $file = $image->resizeImage($file, 640, 320); } } else { $files = array(); } $score = filter::int($this->post->score); $score = $score <= 5 && $score >= 0 ? $score : 0; if (!empty($pid)) { $commentModel = $this->model('comment'); if ($commentModel->create($this->session->id, $pid, $content, $score, $files)) { return json_encode(array('code' => 1, 'result' => 'ok')); } return json_encode(array('code' => 0, 'result' => 'failed')); } return json_encode(array('code' => 2, 'result' => '参数错误')); }
/** * 设置省份 * @return unknown */ function province() { if (empty($this->get->province)) { if (login::user()) { $userModel = $this->model('user'); $user = $userModel->get($this->session->id); $province = $user['province']; } else { $province = $this->session->province; } $p = $this->model('province')->where('id=?', array($province))->select(); if (empty($p)) { return new json(json::OK, NULL, []); } return new json(json::OK, NULL, $p[0]); } else { if (login::user()) { $userModel = $this->model('user'); $userModel->where('id=?', array($this->session->id))->update('province', $this->get->province); } else { $this->session->province = $this->get->province; $this->response->addHeader('Cache-control', 'private'); } return new json(json::OK); } }
/** * 添加建议和反馈 */ function create() { if (!login::user()) { return json_encode(array('code' => 2, 'result' => '尚未登陆')); } $content = $this->post->content; if (!empty($content)) { $messageModel = $this->model('message'); if ($messageModel->create($this->session->id, $content)) { return json_encode(array('code' => 1, 'result' => 'ok')); } } return json_encode(array('code' => 0, 'result' => '提交内容不能为空')); }
/** * 列表 假如是用户的话则获取的为用户的列表 */ function lists() { $start = $this->get->start; $length = $this->get->length; $start = empty($start) ? 0 : $start; $length = empty($length) ? 10 : $length; $filter = array('start' => 0, 'length' => $length, 'order' => array('bankcard.id', 'desc')); if (login::user()) { $filter['uid'] = $this->session->id; } $filter['parameter'] = 'bankcard.bank,bankcard.name,bankcard.number,bankcard.subbank,bankcard.type,province.name as province,city.name as city,bankcard.id,bankcard.uid,province.id as provinceid,city.id as cityid'; $bankcardModel = $this->model('bankcard'); $result = $bankcardModel->fetch($filter); return new json(json::OK, NULL, $result); }
/** * 移除收藏 */ function remove() { if (!login::user()) { return json_encode(array('code' => 2, 'result' => '尚未登陆')); } $id = filter::int($this->post->id); $pid = filter::int($this->post->pid); if (empty($pid) && empty($id)) { return json_encode(array('code' => 3, 'result' => '参数不全')); } if ($this->model('favourite')->remove($id, $pid, $this->session->id)) { return json_encode(array('code' => 1, 'result' => 'ok')); } return json_encode(array('code' => 0, 'result' => 'failed')); }
/** * 获取一个主题内容 */ function information() { $this->response->addHeader('Content-Type', 'application/json'); $id = filter::int($this->get->id); $themeModel = $this->model('theme'); $result = $themeModel->get($id); $result['bigpic'] = empty($result['bigpic']) ? '' : file::realpathToUrl($result['bigpic']); $result['middlepic'] = empty($result['middlepic']) ? '' : file::realpathToUrl($result['middlepic']); $result['smallpic'] = empty($result['smallpic']) ? '' : file::realpathToUrl($result['smallpic']); $result['product'] = $themeModel->product($id); $filter = array('tid' => $id); $filter['parameter'] = 'theme.id,theme.name,theme.description,theme.bigpic,theme.middlepic,theme.smallpic'; $result['theme'] = $this->model('theme')->fetchAll($filter); foreach ($result['theme'] as &$theme) { $theme['smallpic'] = file::realpathToUrl($theme['smallpic']); $theme['middlepic'] = file::realpathToUrl($theme['middlepic']); $theme['bigpic'] = file::realpathToUrl($theme['bigpic']); } foreach ($result['product'] as &$product) { switch ($product['activity']) { case 'sale': $product['activity_description'] = $this->model('sale')->getByPid($product['id']); break; case 'seckill': $product['activity_description'] = $this->model('seckill')->getByPid($product['id']); break; case 'fullcut': $product['activity_description'] = $this->model('fullcutdetail')->getByPid($product['id']); break; default: break; } $product['img'] = $this->model('productimg')->getByPid($product['id']); $product['prototype'] = $this->model('prototype')->getByPid($product['id']); $product['collection'] = $this->model('collection')->getByPid($product['id']); $product['origin'] = $this->model('flag')->getOrigin($product['origin']); } //主题锁 if ($this->model('system')->get('lock', 'theme') && empty($result['tid'])) { if (login::user()) { $this->model('theme_lock')->create($this->session->id, $id); } else { $this->session->theme_lock = $id; } } return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $result)); }
/** * 查看资金流水记录 */ function lists() { $filter = array(); if (login::user()) { $filter['uid'] = $this->session->id; } else { if (!login::admin()) { return new json(json::NOT_LOGIN); } } $start = empty($this->get->start) ? 0 : $this->get->start; $start = intval($start); $length = empty($this->get->length) ? 10 : $this->get->length; $length = intval($length); $filter['start'] = $start; $filter['length'] = $length; $filter['order'] = array(array('time' => 'desc'), array('id' => 'desc')); $result = $this->model('swift')->fetchAll($filter); return new json(json::OK, NULL, $result); }
/** * 新用户注册活动赠送优惠卷 */ function register() { if (!login::user()) { return new json(json::NOT_LOGIN); } //活动id $id = 1; $coupon_id = $this->model('register')->get($id, 'template_coupon'); if (!empty($coupon_id)) { $couponModel = $this->model('coupon'); $coupon = $couponModel->get($coupon_id); if (empty($coupon)) { return new json(json::PARAMETER_ERROR, '优惠券模板不存在'); } $register_logModel = $this->model('register_log'); if (!$register_logModel->checkUser($this->session->id)) { return new json(5, '该用户已经领取过优惠券'); } //优惠代码 $couponno = $this->randomcode(); $couponno = json_decode($couponno)->body; $cid = $couponModel->copyForUser($this->session->id, $couponno, $coupon); if ($cid) { $register_logModel->write($this->session->id, $cid); return new json(json::OK); } return new json(4, '优惠券领取失败'); } }
/** * 用户更改密码 */ function changepwd() { $oldepwd = $this->post->oldpwd; $newpwd = $this->post->newpwd; if (login::user()) { $id = $this->post->id; if (!empty($oldepwd) && !empty($newpwd)) { $userModel = $this->model('user'); if ($userModel->authpwd($id, $oldepwd, $newpwd)) { return json_encode(array('code' => 1, 'result' => '密码更改成功')); } return json_encode(array('code' => 2, 'result' => '旧密码不正确')); } else { return json_encode(array('code' => 3, 'result' => '新密码或旧密码不得为空')); } } return json_encode(array('code' => 0, 'result' => '尚未登陆')); }
/** * 提现请求列表 */ function lists() { $start = intval($this->get->start); $length = intval($this->get->length); $start = empty($start) ? 0 : $start; $length = empty($length) ? 10 : $length; $filter = array('start' => $start, 'length' => $length, 'order' => array('drawal.time', 'desc')); if (login::user()) { $filter['uid'] = $this->session->id; } else { if (!login::admin()) { return new json(json::NOT_LOGIN); } } $filter['parameter'] = 'drawal.money,drawal.handle,drawal.handletime,drawal.time,drawal.id,user.username,user.telephone,bankcard.number,bankcard.name,bankcard.bank'; $drawalModel = $this->model('drawal'); $result = $drawalModel->fetch($filter); return new json(json::OK, NULL, $result, true); }
/** * 获得指定地址id的信息 */ function information() { if (!login::user()) { return new json(json::NOT_LOGIN); } $id = filter::int($this->get->id); $addressModel = $this->model('address'); $filter = array('parameter' => 'city.name as city,province.name as province,province.id as provinceid,city.id as cityid,address.id,address.uid,address.county,address.address,address.zcode,adddress.host,address.name,address.telephone', 'id' => $id, 'uid' => $this->session->id); $address = $addressModel->fetchAll($filter); if (isset($address[0])) { return new json(json::OK, NULL, $address[0]); } return new json(json::OK, NULL, array()); }
/** * 关闭退款申请 */ function remove() { //订单id $id = filter::int($this->post->id); if (login::user()) { $refundModel = $this->model('refund'); if ($refundModel->close($id)) { return json_encode(array('code' => 1, 'result' => 'ok')); } return json_encode(array('code' => 0, 'result' => '取消失败')); } return json_encode(array('code' => 2, 'result' => '尚未登陆')); }
/** * 取消订单接口 */ function quit() { if (!login::user()) { return json_encode(array('code' => 2, 'result' => '尚未登陆')); } $id = filter::int($this->post->id); $orderModel = $this->model('orderlist'); $order = $orderModel->get($id); if (empty($order)) { return json_encode(array('code' => 3, 'result' => '没有订单')); } if ($order['status'] == orderlistModel::STATUS_PAYING) { if ($orderModel->quit($id)) { return json_encode(array('code' => 1, 'result' => 'ok')); } } return json_encode(array('code' => 0, 'result' => '订单状态无法更改')); }
/** * 获得一个商品的所有详细信息 */ function information() { $this->response->addHeader('Content-Type', 'application/json'); $pid = empty(filter::int($this->get->pid)) ? 0 : filter::int($this->get->pid); $productModel = $this->model('product'); $product = $productModel->get($pid); if (!empty($product)) { $prototypeModel = $this->model('prototype'); $prototype = $prototypeModel->getByPid($pid); $product['prototype'] = $prototype; $collectionModel = $this->model('collection'); $collection = $collectionModel->getByPid($pid); $product['collection'] = $collection; $product['category'] = $this->model('category')->get($product['category'], 'name'); $product['brand'] = $this->model('brand')->get($product['bid'], 'name'); $product['img'] = $this->model('productimg')->getByPid($pid); unset($product['bid']); switch ($product['activity']) { case 'sale': $product['activity_description'] = $this->model('sale')->getByPid($product['id']); break; case 'seckill': $product['activity_description'] = $this->model('seckill')->getByPid($product['id']); break; case 'fullcut': $product['activity_description'] = $this->model('fullcutdetail')->getByPid($product['id']); break; default: break; } if (login::user() && $this->model('favourite')->checkProduct($this->session->id, $product['id'])) { $product['favourite'] = true; } return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $product)); } return json_encode(array('code' => 0, 'result' => '商品不存在')); }
/** * 将购物车中的物品生成订单 */ function order() { $this->response->addHeader('Content-Type', 'application/json'); if (!login::user()) { return json_encode(array('code' => 3, 'result' => '尚未登陆')); } $preorder = $this->post->preorder; //优惠前的价格 //订单货款 $ordergoodsamount = 0; //购物车中的商品 $cartModel = $this->model('cart'); $uid = $this->session->id; $cart = $cartModel->getByUid($uid); //订单详情 $orderdetail = array(); $collectionModel = $this->model('collection'); $prototypeModel = $this->model('prototype'); //优惠金额 $discount = 0; $couponModel = $this->model('coupon'); //要使用的优惠卷信息 $coupon = empty($this->post->coupon) ? '' : $this->post->coupon; //存储满减商品 $fullcut_temp = array(); //存储没有参加活动商品信息 $coupon_temp = array(); foreach ($cart as $product) { $pricestocksku = $collectionModel->find($product['pid'], unserialize($product['content'])); $prototype = $prototypeModel->getByPid($product['pid']); $prototype = (new prototype())->format($prototype, $product['content']); if (!empty($pricestocksku)) { $product['price'] = $pricestocksku['price']; $product['sku'] = $pricestocksku['sku']; } $t_orderdetail = array('sku' => $product['sku'], 'pid' => $product['pid'], 'productname' => $product['name'], 'brand' => $this->model('brand')->get($product['bid'], 'name'), 'unitprice' => $product['price'], 'content' => $product['content'], 'prototype' => $prototype, 'origin' => $product['origin'], 'score' => $product['score'], 'num' => $product['num']); //商品详情加入到数组 $orderdetail[] = $t_orderdetail; switch ($product['activity']) { case 'seckill': $seckillModel = $this->model('seckill'); $price = $seckillModel->getPrice($product['pid']); if ($price !== NULL) { $discount += ($product['price'] - $price) * $product['num']; $ordergoodsamount += $price * $product['num']; } else { $ordergoodsamount += $product['price'] * $product['num']; } break; case 'sale': $saleModel = $this->model('sale'); $price = $saleModel->getPrice($product['pid']); if ($price !== NULL) { $discount += ($product['price'] - $price) * $product['num']; $ordergoodsamount += $price * $product['num']; } else { $ordergoodsamount += $product['price'] * $product['num']; } break; case 'fullcut': //取出所有满减规则的商品 $fullcut_temp[] = $product; break; default: $coupon_temp[] = $product; } } //单独计算不同的满减规则 $fullcutHelper = new fullcut($this->model('fullcutdetail'), $fullcut_temp); //最终价格 $ordergoodsamount += $fullcutHelper->getPrice(); //免去价格 $discount += $fullcutHelper->getMinus(); //计算优惠 $couponHelper = new coupon($coupon, $uid, $this->model('coupon'), $coupon_temp); $ordergoodsamount += $couponHelper->getPrice(); $discount += $couponHelper->getMinus(); //是否减少优惠券使用次数 if ($couponHelper->getMinus() > 0 && !$preorder) { $couponModel->increaseTimes($coupon, -1); } //支付方式 $paytype = $this->post->paytype; if (empty($paytype)) { return json_encode(array('code' => 4, 'result' => '没有支付方式')); } //支付单号 $paynumber = ''; //运费 根据订单金额计算运费 $shipid = filter::int($this->post->shipid); if (empty($shipid)) { return json_encode(array('code' => 5, 'result' => '错误的配送方案')); } $shipModel = $this->model('ship'); $ship = $shipModel->get($shipid); if (empty($ship)) { return json_encode(array('code' => 5, 'result' => '错误的配送方案')); } $feeamount = $shipModel->getPrice($shipid, $ordergoodsamount); //订单编号 $orderno = (new order())->swift($this->session->id); //订单税款 免税 $ordertaxamount = 0; //订单生成时间 $createtime = $_SERVER['REQUEST_TIME']; //交易时间 $tradetime = 0; //订单总金额 $ordertotalamount = $feeamount + $ordertaxamount + $ordergoodsamount; //成交总价 已经支付的价格 $totalamount = 0; //收件人 $addressid = filter::int($this->post->addressid); $address_parameter = 'city.name as city,province.name as province,address.county,address.address,address.zcode,address.name,address.telephone'; $address = $this->model('address')->get($addressid, $address_parameter); if (empty($address)) { if (empty($preorder)) { return json_encode(array('code' => 6, 'result' => '错误的配送地址')); } else { $address = array('name' => '', 'telephone' => '', 'address' => '', 'province' => '', 'city' => '', 'county' => '', 'zcode' => ''); } } $consignee = $address['name']; $consigneetel = $address['telephone']; $consigneeaddress = $address['address']; $consigneeprovince = $address['province']; $consigneecity = $address['city']; $consigneecounty = $address['county']; $zipcode = $address['zcode']; //物流方式 $postmode = $ship['code']; //运单号 $waybills = ''; //发件人 $sendername = $this->model('system')->get('sendername', 'system'); //公司名称 $companyname = $this->model('system')->get('companyname', 'system'); //备注信息 $note = ''; //订单状态 $status = 0; //订单来源 $client = $this->post->client; /** * 财付通专用,标注是否已经报过报过接口 1没有 2已经报过 */ $action_type = '1'; $money = 0; //余额支付 /* $extra_money = $this->model('user')->get($uid,'money'); if ($extra_money >= $ordertotalamount) { //余额足够支付订单 $extra_money -= $ordertotalamount; $ordertotalamount = 0; $money = $ordertotalamount; $status = 1; } else { $ordertotalamount -= $extra_money; $money = $extra_money; } if (!$preorder) { //更改用户余额 $this->model('user')->money($uid,-$money); } */ $data = array(NULL, $uid, $paytype, $paynumber, $ordertotalamount, $money, $orderno, $ordertaxamount, $ordergoodsamount, $feeamount, $tradetime, $createtime, $totalamount, $consignee, $consigneetel, $consigneeaddress, $consigneeprovince, $consigneecity, $consigneecounty, $postmode, $waybills, $sendername, $companyname, $zipcode, $note, $status, $discount, $client, $action_type); if ($preorder) { $order = array('id' => NULL, 'uid' => $uid, 'paytype' => $paytype, 'paynumber' => $paynumber, 'ordertotalamount' => $ordertotalamount, 'money' => $money, 'orderno' => $orderno, 'ordertaxamount' => $ordertaxamount, 'ordergoodsamount' => $ordergoodsamount, 'feeamount' => $feeamount, 'tradetime' => $tradetime, 'createtime' => $createtime, 'totalamount' => $totalamount, 'consignee' => $consignee, 'consigneetel' => $consigneetel, 'consigneeaddress' => $consigneeaddress, 'consigneeprovince' => $consigneeprovince, 'consigneecity' => $consigneecity, 'consigneecounty' => $consigneecounty, 'postmode' => $postmode, 'waybills' => $waybills, 'sendername' => $sendername, 'companyname' => $companyname, 'zipcode' => $zipcode, 'note' => $note, 'status' => $status, 'discount' => $discount, 'client' => $client, 'action_type' => $action_type); $order['orderdetail'] = $orderdetail; return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $order)); } else { $orderModel = $this->model('orderlist'); $oid = $orderModel->create($data, $orderdetail); if ($oid) { $cartModel->clear($uid); //用户订单数量+1 $this->model('user')->where('id=?', array($uid))->increase('ordernum', 1); //商品订单数量+1 foreach ($orderdetail as $ordergoods) { $this->model('product')->where('id=?', array($ordergoods['pid']))->increase('ordernum', 1); } $order = $orderModel->get($oid); $order['orderdetail'] = $orderModel->getOrderDetail($oid); return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $order)); } return json_encode(array('code' => 2, 'result' => '创建订单失败')); } }