123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970 |
- <?php
- namespace app\api\controller\order;
- use app\admin\model\system\{
- SystemAttachment, ShippingTemplates
- };
- use app\admin\model\user\User;
- use app\models\routine\RoutineFormId;
- use app\models\user\UserBill;
- use crmeb\repositories\OrderRepository;
- use app\models\store\{
- StoreBargainUser,
- StoreCart,
- StoreCoupon,
- StoreCouponIssue,
- StoreCouponUser,
- StoreOrder,
- StoreOrderCartInfo,
- StoreOrderStatus,
- StorePink,
- StoreProductReply
- };
- use app\models\system\SystemStore;
- use app\models\order\Line;
- use app\models\user\UserAddress;
- use app\models\user\UserLevel;
- use app\Request;
- use crmeb\services\{
- CacheService,
- ExpressService,
- SystemConfigService,
- UtilService
- };
- use think\facade\Db;
- use crmeb\utils\Line as LineJob;
- class StoreOrderController
- {
-
- public function confirm(Request $request)
- {
- $temp = ShippingTemplates::get(1);
- if (!$temp) return app('json')->fail('默认模板未配置,无法下单');
- list($cartId) = UtilService::postMore(['cartId'], $request, true);
- if (!is_string($cartId) || !$cartId) return app('json')->fail('请提交购买的商品');
- $uid = $request->uid();
- $cartGroup = StoreCart::getUserProductCartList($uid, $cartId, 1);
- if (count($cartGroup['invalid'])) {
- return app('json')->fail($cartGroup['invalid']);
- }
- if (!$cartGroup['valid']) return app('json')->fail('请提交购买的商品');
- $cartInfo = $cartGroup['valid'];
- $addr = UserAddress::where('uid', $uid)->where('is_default', 1)->find();
- $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, $addr);
- if ($priceGroup === false) {
- return app('json')->fail(StoreOrder::getErrorInfo('运费模板不存在'));
- }
- $other = [
- 'offlinePostage' => sys_config('offline_postage'),
- 'integralRatio' => sys_config('integral_ratio')
- ];
- $usableCoupons = StoreCouponUser::getUsableCouponList($uid, $cartGroup, $priceGroup['totalPrice']);
- $usableCoupon = isset($usableCoupons[0]) ? $usableCoupons[0] : null;
- $cartIdA = explode(',', $cartId);
- $seckill_id = 0;
- $combination_id = 0;
- $bargain_id = 0;
- $activity_id = 0;
- $live_id = 0;
- $is_gift = 0;
- if (count($cartIdA) == 1) {
- $seckill_id = StoreCart::where('id', $cartId)->value('seckill_id');
- $combination_id = StoreCart::where('id', $cartId)->value('combination_id');
- $bargain_id = StoreCart::where('id', $cartId)->value('bargain_id');
- $activity_id = StoreCart::where('id', $cartId)->value('activity_id');
- $live_id = StoreCart::where('id', $cartId)->value('live_id');
- $is_gift = StoreCart::where('id', $cartId)->value('is_gift');
- }
- $use_integral_pink = Db::name('store_combination')->alias('c')->join('store_product p', 'c.product_id=p.id')->where('c.id', '=', $combination_id)->value('cost_integral');
- $data['use_integral_pink'] = $use_integral_pink;
- $data['deduction'] = $seckill_id || $combination_id || $bargain_id;
- $data['usableCoupon'] = $usableCoupon;
- $data['addressInfo'] = UserAddress::getUserDefaultAddress($uid);
- $data['seckill_id'] = $seckill_id;
- $data['combination_id'] = $combination_id;
- $data['bargain_id'] = $bargain_id;
- $data['activity_id'] = $activity_id;
- $data['live_id'] = $live_id;
- $data['cartInfo'] = $cartInfo;
- $data['priceGroup'] = $priceGroup;
- $data['orderKey'] = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
- $data['offlinePostage'] = $other['offlinePostage'];
- $vipId = UserLevel::getUserLevel($uid);
- $user = $request->user();
- if (isset($user['pwd'])) unset($user['pwd']);
- $user['vip'] = $vipId !== false ? true : false;
- if ($user['vip']) {
- $user['vip_id'] = $vipId;
- $user['discount'] = UserLevel::getUserLevelInfo($vipId, 'discount');
- }
- $data['is_gift'] = $is_gift;
- $data['userInfo'] = $user;
- $data['integralRatio'] = $other['integralRatio'];
- $data['offline_pay_status'] = (int)sys_config('offline_pay_status') ?? (int)2;
- $data['store_self_mention'] = (int)sys_config('store_self_mention') ?? 0;
- $data['system_store'] = ($res = SystemStore::getStoreDispose()) ? $res : [];
- return app('json')->successful($data);
- }
-
- public function computedOrder(Request $request, $key)
- {
- if (!$key) return app('json')->fail('参数错误!');
- $uid = $request->uid();
- if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
- return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
- list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $activity_id, $live_id, $shipping_type, $use_integral_pink,$is_num) = UtilService::postMore([
- 'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['activity_id', 0], ['live_id', 0], ['shipping_type', 1], ['use_integral_pink', sys_config('pink_cost_integral')],['is_num',0]], $request, true);
- $payType = strtolower($payType);
- if ($bargainId) {
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);
- if (!$bargainUserTableId)
- return app('json')->fail('砍价失败');
- $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
- if ($status == 3)
- return app('json')->fail('砍价已支付');
- StoreBargainUser::setBargainUserStatus($bargainId, $uid);
- }
- if ($pinkId) {
- if (StorePink::getIsPinkUid($pinkId, $request->uid()))
- return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
- if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
- return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
- }
- if ($activity_id) {
-
- }
- if ($live_id) {
-
- }
- $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $activity_id, $live_id, true, 0, $shipping_type,$use_integral_pink,$is_num);
- if ($priceGroup)
- return app('json')->status('NONE', 'ok', $priceGroup);
- else
- return app('json')->fail(StoreOrder::getErrorInfo('计算失败'));
- }
-
- public function create(Request $request, $key)
- {
- if (!$key) return app('json')->fail('参数错误!');
- $uid = $request->uid();
- if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
- return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
- list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $activity_id, $live_id, $from, $shipping_type, $real_name, $phone, $storeId, $use_integral_pink, $isAutoPink,$is_gift,$spread,$is_num,$pink_num,$line_id,$is_wdc) = UtilService::postMore([
- 'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['activity_id', 0], ['live_id', 0], ['from', 'weixin'], ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0], ['use_integral_pink', sys_config('pink_cost_integral')], ['is_auto_pink', 0],['is_gift',0],['spread',0],['is_num',0],['pink_num',1],['line_id',0],['is_wdc',0]
- ], $request, true);
- $payType = strtolower($payType);
- if ($bargainId) {
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId, $uid);
- if (!$bargainUserTableId)
- return app('json')->fail('砍价失败');
- $status = StoreBargainUser::getBargainUserStatusEnd($bargainUserTableId);
- if ($status == 3)
- return app('json')->fail('砍价已支付');
- StoreBargainUser::setBargainUserStatus($bargainId, $uid);
- }
- $top_num=sys_config('pink_suceess_num');
- $num=StorePink::where('uid',$uid)->where('is_refund',0)->where('status',2)->whereTime('stop_time','today')->count();
-
- if($combinationId && $isAutoPink){
- if($num>=$top_num) return app('json')->fail('今日拼团已达上限');
- $auto_pink=StoreOrder::where('uid',$uid)->where('combination_id','<>',0)->where('is_del',0)->where('is_ok',0)->find();
- if($auto_pink){
- return app('json')->fail('拼团正在进行');
- }
- }
- if ($pinkId) {
- $people = StorePink::where("id", $pinkId)->value('people');
- $count = StoreOrder::where("pink_id={$pinkId} and is_del=0")->count();
- if ($count >= $people) {
- return app('json')->fail('有人在您前面付款,请稍后再试!' . $people . '-' . $count);
- }
- if (StorePink::getIsPinkUid($pinkId, $request->uid()))
- return app('json')->status('ORDER_EXIST', '订单生成失败,你已经在该团内不能再参加了', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
- if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
- return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
- if (StorePink::isPinkStatus($pinkId))
- return app('json')->fail('拼团已经完成,无法支付!');
- }
- if ($activity_id) {
-
- }
- if ($live_id) {
-
- }
- $isChannel = 1;
- if ($from == 'weixin')
- $isChannel = 0;
- elseif ($from == 'weixinh5')
- $isChannel = 2;
- elseif ($from == 'integral')
- $isChannel = 3;
- elseif ($from == 'wdc')
- $isChannel = 4;
- $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $activity_id, $live_id, false, $isChannel, $shipping_type, $real_name, $phone, $storeId, intval($use_integral_pink), $isAutoPink,$is_gift,$spread,$is_num,$pink_num,$line_id,$is_wdc);
- if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
- $orderId = $order['order_id'];
- $info = compact('orderId', 'key');
- if ($orderId) {
- event('OrderCreated', [$order]);
- event('ShortMssageSend', [$orderId, 'AdminPlaceAnOrder']);
- switch ($payType) {
- case "weixin":
- $orderInfo = StoreOrder::where('order_id', $orderId)->find();
- if (!$orderInfo || !isset($orderInfo['paid'])) return app('json')->fail('支付订单不存在!');
- $orderInfo = $orderInfo->toArray();
- if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
-
- if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
-
- $payPriceStatus = StoreOrder::jsPayPrice($orderId, $uid, $formId);
- if ($payPriceStatus)
- return app('json')->status('success', '微信支付成功', $info);
- else
- return app('json')->status('pay_error', StoreOrder::getErrorInfo());
- } else {
- try {
- if ($from == 'routine') {
- $jsConfig = OrderRepository::jsPay($orderId);
- } else if ($from == 'weixinh5') {
- $jsConfig = OrderRepository::h5Pay($orderId);
- } else {
- $jsConfig = OrderRepository::wxPay($orderId);
- }
- } catch (\Exception $e) {
- return app('json')->status('pay_error', $e->getMessage(), $info);
- }
- $info['jsConfig'] = $jsConfig;
- if ($from == 'weixinh5') {
- return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
- } else {
- return app('json')->status('wechat_pay', '订单创建成功', $info);
- }
- }
- break;
- case 'yue':
- if (StoreOrder::yuePay($orderId, $request->uid(), $formId))
- return app('json')->status('success', '余额支付成功', $info);
- else {
- $errorinfo = StoreOrder::getErrorInfo();
- if (is_array($errorinfo))
- return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
- else
- return app('json')->status('pay_error', $errorinfo);
- }
- break;
- case 'integral':
- if (StoreOrder::integralPay($orderId, $request->uid(), $formId))
- return app('json')->status('success', '积分支付成功', $info);
- else {
- $errorinfo = StoreOrder::getErrorInfo();
- if (is_array($errorinfo))
- return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
- else
- return app('json')->status('pay_error', $errorinfo);
- }
- break;
- case 'wdc':
- if (StoreOrder::wdcPay($orderId, $request->uid(), $formId))
- return app('json')->status('success', 'wdc支付成功', $info);
- else {
- $errorinfo = StoreOrder::getErrorInfo();
- if (is_array($errorinfo))
- return app('json')->status($errorinfo['status'], $errorinfo['msg'], $info);
- else
- return app('json')->status('pay_error', $errorinfo);
- }
- break;
- case 'offline':
- return app('json')->status('success', '订单创建成功', $info);
- break;
- }
- } else return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败!'));
- }
-
- public function again(Request $request)
- {
- list($uni) = UtilService::postMore([
- ['uni', ''],
- ], $request, true);
- if (!$uni) return app('json')->fail('参数错误!');
- $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
- if (!$order) return app('json')->fail('订单不存在!');
- $order = StoreOrder::tidyOrder($order, true);
- $res = [];
- foreach ($order['cartInfo'] as $v) {
- if ($v['combination_id']) return app('json')->fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
- else if ($v['bargain_id']) return app('json')->fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
- else if ($v['seckill_id']) return app('json')->ail('秒杀产品不能再来一单,请在秒杀产品内自行下单!');
- else if ($v['activity_id']) return app('json')->ail('活动产品不能再来一单,请在秒杀产品内自行下单!');
- else $res[] = StoreCart::setCart($request->uid(), $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
- }
- $cateId = [];
- foreach ($res as $v) {
- if (!$v) return app('json')->fail('再来一单失败,请重新下单!');
- $cateId[] = $v['id'];
- }
- event('OrderCreateAgain', implode(',', $cateId));
- return app('json')->successful('ok', ['cateId' => implode(',', $cateId)]);
- }
-
- public function pay(Request $request)
- {
- list($uni, $paytype, $from) = UtilService::postMore([
- ['uni', ''],
- ['paytype', 'weixin'],
- ['from', 'weixin']
- ], $request, true);
- if (!$uni) return app('json')->fail('参数错误!');
- $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
- if (!$order)
- return app('json')->fail('订单不存在!');
- if ($order['paid'])
- return app('json')->fail('该订单已支付!');
- if ($order['pink_id']) if (StorePink::isPinkStatus($order['pink_id']))
- return app('json')->fail('该订单已失效!');
- if ($order['pink_id']) {
- $data = StorePink::where('id', $order['pink_id'])->field("k_id,people")->find();
- $count = StoreOrder::where("pink_id", $order['pink_id'])->where("is_del=0")->where("uid!={$request->uid()}")->count();
- if ($count >= $data['people']) {
- return app('json')->fail('有人在您前面付款,请稍后再试!');
- }
- if (StorePink::isPinkStatus($order['pink_id']))
- return app('json')->fail('拼团已经完成,无法支付!');
- }
- if ($from == 'weixin') {
- if (in_array($order->is_channel, [1, 2,3,4]))
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
- }
- if ($from == 'weixinh5') {
- if (in_array($order->is_channel, [0, 1,3,4]))
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
- }
- if ($from == 'routine') {
- if (in_array($order->is_channel, [0, 2,3,4]))
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
- }
- if ($from == 'integral') {
- if (in_array($order->is_channel, [0, 2,1,4]))
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
- }
- if ($from == 'wdc') {
- if (in_array($order->is_channel, [0, 2,1,3]))
- $order['order_id'] = mt_rand(100, 999) . '_' . $order['order_id'];
- }
- $order['pay_type'] = $paytype;
- switch ($order['pay_type']) {
- case 'weixin':
- try {
- if ($from == 'routine') {
- $jsConfig = OrderRepository::jsPay($order);
- } else if ($from == 'weixinh5') {
- $jsConfig = OrderRepository::h5Pay($order);
- } else {
- $jsConfig = OrderRepository::wxPay($order);
- }
- } catch (\Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- if ($from == 'weixinh5') {
- return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
- } else {
- return app('json')->status('wechat_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
- }
- break;
- case 'yue':
- if (StoreOrder::yuePay($order['order_id'], $request->uid()))
- return app('json')->status('success', '余额支付成功');
- else {
- $error = StoreOrder::getErrorInfo();
- return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
- }
- break;
- case 'integral':
- if (StoreOrder::integralPay($order['order_id'], $request->uid()))
- return app('json')->status('success', '余额支付成功');
- else {
- $error = StoreOrder::getErrorInfo();
- return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
- }
- break;
- case 'wdc':
- if (StoreOrder::wdcPay($order['order_id'], $request->uid()))
- return app('json')->status('success', '余额支付成功');
- else {
- $error = StoreOrder::getErrorInfo();
- return app('json')->fail(is_array($error) && isset($error['msg']) ? $error['msg'] : $error);
- }
- break;
- case 'offline':
- StoreOrder::createOrderTemplate($order);
- if (StoreOrder::setOrderTypePayOffline($order['order_id']))
- return app('json')->status('success', '订单创建成功');
- else
- return app('json')->status('success', '支付失败');
- break;
- }
- return app('json')->fail('支付方式错误');
- }
-
- public function lst(Request $request)
- {
- list($type, $page, $limit, $search) = UtilService::getMore([
- ['type', ''],
- ['page', 0],
- ['limit', ''],
- ['search', ''],
- ], $request, true);
- return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
- }
-
- public function detail(Request $request, $uni)
- {
- if (!strlen(trim($uni))) return app('json')->fail('参数错误');
- $order = StoreOrder::getUserOrderDetail($request->uid(), $uni);
- if (!$order) return app('json')->fail('订单不存在');
- $order = $order->toArray();
-
- $store_self_mention = sys_config('store_self_mention');
-
- if ($store_self_mention == 0) $order['shipping_type'] = 1;
- if ($order['verify_code']) {
- $verify_code = $order['verify_code'];
- $verify[] = substr($verify_code, 0, 4);
- $verify[] = substr($verify_code, 4, 4);
- $verify[] = substr($verify_code, 8);
- $order['_verify_code'] = implode(' ', $verify);
- }
- $order['add_time_y'] = date('Y-m-d', $order['add_time']);
- $order['add_time_h'] = date('H:i:s', $order['add_time']);
- $order['system_store'] = SystemStore::getStoreDispose($order['store_id']);
- if ($order['shipping_type'] === 2 && $order['verify_code']) {
- $name = $order['verify_code'] . '.jpg';
- $imageInfo = SystemAttachment::getInfo($name, 'name');
- $siteUrl = sys_config('site_url');
- if (!$imageInfo) {
- $imageInfo = UtilService::getQRCodePath($order['verify_code'], $name);
- if (is_array($imageInfo)) {
- SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
- $url = $imageInfo['dir'];
- } else
- $url = '';
- } else $url = $imageInfo['att_dir'];
- if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
- $order['code'] = $url;
- }
- $order['mapKey'] = sys_config('tengxun_map_key');
- return app('json')->successful('ok', StoreOrder::tidyOrder($order, true, true));
- }
-
- public function del(Request $request)
- {
- list($uni) = UtilService::postMore([
- ['uni', ''],
- ], $request, true);
- if (!$uni) return app('json')->fail('参数错误!');
- $res = StoreOrder::removeOrder($uni, $request->uid());
- if ($res)
- return app('json')->successful();
- else
- return app('json')->fail(StoreOrder::getErrorInfo());
- }
-
- public function take(Request $request)
- {
- list($uni) = UtilService::postMore([
- ['uni', ''],
- ], $request, true);
- if (!$uni) return app('json')->fail('参数错误!');
- $res = StoreOrder::takeOrder($uni, $request->uid());
- if ($res) {
- $order_info = StoreOrder::where('order_id', $uni)->find();
- $gain_integral = intval($order_info['gain_integral']);
- $gain_coupon = StoreCouponIssue::alias('a')
- ->join('store_coupon b', 'a.cid = b.id')
- ->where('a.status', 1)
- ->where('a.is_full_give', 1)
- ->where('a.is_del', 0)
- ->where('a.full_reduction', '<=', $order_info['total_price'])
- ->sum('b.coupon_price');
- return app('json')->successful(['gain_integral' => $gain_integral, 'gain_coupon' => $gain_coupon]);
- } else
- return app('json')->fail(StoreOrder::getErrorInfo());
- }
-
- public function express(Request $request, $uni)
- {
- if (!$uni || !($order = StoreOrder::getUserOrderDetail($request->uid(), $uni))) return app('json')->fail('查询订单不存在!');
- if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return app('json')->fail('该订单不存在快递单号!');
- $cacheName = $uni . $order['delivery_id'];
- $result = CacheService::get($cacheName, null);
- if ($result === NULL) {
- $result = ExpressService::query($order['delivery_id']);
- if (is_array($result) &&
- isset($result['result']) &&
- isset($result['result']['deliverystatus']) &&
- $result['result']['deliverystatus'] >= 3)
- $cacheTime = 0;
- else
- $cacheTime = 1800;
- CacheService::set($cacheName, $result, $cacheTime);
- }
- $orderInfo = [];
- $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('cart_info', 'unique') ?? [];
- $info = [];
- $cartNew = [];
- foreach ($cartInfo as $k => $cart) {
- $cart = json_decode($cart, true);
- $cartNew['cart_num'] = $cart['cart_num'];
- $cartNew['truePrice'] = $cart['truePrice'];
- $cartNew['productInfo']['image'] = $cart['productInfo']['image'];
- $cartNew['productInfo']['store_name'] = $cart['productInfo']['store_name'];
- $cartNew['productInfo']['unit_name'] = $cart['productInfo']['unit_name'] ?? '';
- array_push($info, $cartNew);
- unset($cart);
- }
- $orderInfo['delivery_id'] = $order['delivery_id'];
- $orderInfo['delivery_name'] = $order['delivery_name'];
- $orderInfo['delivery_type'] = $order['delivery_type'];
- $orderInfo['cartInfo'] = $info;
- return app('json')->successful(['order' => $orderInfo, 'express' => $result ? $result : []]);
- }
-
- public function comment(Request $request)
- {
- $group = UtilService::postMore([
- ['unique', ''], ['comment', ''], ['pics', ''], ['product_score', 5], ['service_score', 5]
- ], $request);
- $unique = $group['unique'];
- unset($group['unique']);
- if (!$unique) return app('json')->fail('参数错误!');
- $cartInfo = StoreOrderCartInfo::where('unique', $unique)->find();
- $uid = $request->uid();
- $user_info = User::get($uid);
- $group['nickname'] = $user_info['nickname'];
- $group['avatar'] = $user_info['avatar'];
- if (!$cartInfo) return app('json')->fail('评价产品不存在!');
- $orderUid = StoreOrder::getOrderInfo($cartInfo['oid'], 'uid')['uid'];
- if ($uid != $orderUid) return app('json')->fail('评价产品不存在!');
- if (StoreProductReply::be(['oid' => $cartInfo['oid'], 'unique' => $unique]))
- return app('json')->fail('该产品已评价!');
- $group['comment'] = htmlspecialchars(trim($group['comment']));
- if ($group['product_score'] < 1) return app('json')->fail('请为产品评分');
- else if ($group['service_score'] < 1) return app('json')->fail('请为商家服务评分');
- if ($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
- else if ($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
- else if ($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
- else $productId = $cartInfo['product_id'];
- if ($group['pics']) $group['pics'] = json_encode(is_array($group['pics']) ? $group['pics'] : explode(',', $group['pics']));
- $group = array_merge($group, [
- 'uid' => $uid,
- 'oid' => $cartInfo['oid'],
- 'unique' => $unique,
- 'product_id' => $productId,
- 'add_time' => time(),
- 'reply_type' => 'product'
- ]);
- StoreProductReply::beginTrans();
- $res = StoreProductReply::reply($group, 'product');
- if (!$res) {
- StoreProductReply::rollbackTrans();
- return app('json')->fail('评价失败!');
- }
- try {
- StoreOrder::checkOrderOver($cartInfo['oid']);
- } catch (\Exception $e) {
- StoreProductReply::rollbackTrans();
- return app('json')->fail($e->getMessage());
- }
- StoreProductReply::commitTrans();
- event('UserCommented', $res);
- event('AdminNewPush');
- return app('json')->successful();
- }
-
- public function data(Request $request)
- {
- return app('json')->successful(StoreOrder::getOrderData($request->uid()));
- }
-
- public function refund_reason()
- {
- $reason = sys_config('stor_reason') ?: [];
- $reason = str_replace("\r\n", "\n", $reason);
- $reason = explode("\n", $reason);
- return app('json')->successful($reason);
- }
-
- public function refund_verify(Request $request)
- {
- $data = UtilService::postMore([
- ['text', ''],
- ['refund_reason_wap_img', ''],
- ['refund_reason_wap_explain', ''],
- ['uni', '']
- ], $request);
- $uni = $data['uni'];
- unset($data['uni']);
- if ($data['refund_reason_wap_img']) $data['refund_reason_wap_img'] = explode(',', $data['refund_reason_wap_img']);
- if (!$uni || $data['text'] == '') return app('json')->fail('参数错误!');
- $res = StoreOrder::orderApplyRefund($uni, $request->uid(), $data['text'], $data['refund_reason_wap_explain'], $data['refund_reason_wap_img']);
- if ($res)
- return app('json')->successful('提交申请成功');
- else
- return app('json')->fail(StoreOrder::getErrorInfo());
- }
-
- public function cancel(Request $request)
- {
- list($id) = UtilService::postMore([['id', 0]], $request, true);
- if (!$id) return app('json')->fail('参数错误');
- if (StoreOrder::cancelOrder($id, $request->uid()))
- return app('json')->successful('取消订单成功');
- return app('json')->fail(StoreOrder::getErrorInfo('取消订单失败'));
- }
-
- public function product(Request $request)
- {
- list($unique) = UtilService::postMore([['unique', '']], $request, true);
- if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return app('json')->fail('评价产品不存在!');
- $cartInfo = $cartInfo->toArray();
- $cartProduct = [];
- $cartProduct['cart_num'] = $cartInfo['cart_info']['cart_num'];
- $cartProduct['productInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['image']) ? $cartInfo['cart_info']['productInfo']['image'] : '';
- $cartProduct['productInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['price']) ? $cartInfo['cart_info']['productInfo']['price'] : 0;
- $cartProduct['productInfo']['store_name'] = isset($cartInfo['cart_info']['productInfo']['store_name']) ? $cartInfo['cart_info']['productInfo']['store_name'] : '';
- if (isset($cartInfo['cart_info']['productInfo']['attrInfo'])) {
- $cartProduct['productInfo']['attrInfo']['product_id'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['product_id']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['product_id'] : '';
- $cartProduct['productInfo']['attrInfo']['suk'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['suk']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['suk'] : '';
- $cartProduct['productInfo']['attrInfo']['price'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['price']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['price'] : '';
- $cartProduct['productInfo']['attrInfo']['image'] = isset($cartInfo['cart_info']['productInfo']['attrInfo']['image']) ? $cartInfo['cart_info']['productInfo']['attrInfo']['image'] : '';
- }
- $cartProduct['product_id'] = isset($cartInfo['cart_info']['product_id']) ? $cartInfo['cart_info']['product_id'] : 0;
- $cartProduct['combination_id'] = isset($cartInfo['cart_info']['combination_id']) ? $cartInfo['cart_info']['combination_id'] : 0;
- $cartProduct['seckill_id'] = isset($cartInfo['cart_info']['seckill_id']) ? $cartInfo['cart_info']['seckill_id'] : 0;
- $cartProduct['bargain_id'] = isset($cartInfo['cart_info']['bargain_id']) ? $cartInfo['cart_info']['bargain_id'] : 0;
- $cartProduct['order_id'] = StoreOrder::where('id', $cartInfo['oid'])->value('order_id');
- return app('json')->successful($cartProduct);
- }
-
- public function get_noPay(Request $request)
- {
- return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), 0, 0, 0, ''));
- }
-
- public function express_query(Request $request)
- {
- $param = UtilService::getMore([
- 'id'
- ], $request);
- $res = Db::name('store_order')->alias('o')->join('express e', 'o.delivery_name=e.name')->field("o.delivery_name as delivery_name,o.delivery_id as delivery_id,e.code as code")->where("o.id", $param['id'])->select()->toArray();
- if (empty($res)) {
- return app('json')->fail('找不到订单');
- }
- if (!$res[0]['delivery_id'] || !$res[0]['code']) {
- return app('json')->fail('快递单号不存在或找不到该快递公司');
- }
-
- $key = 'YOBlimCZ5185';
- $customer = '5B24735E58787695A978711842716651';
- $param = array(
- 'com' => $res[0]['code'],
- 'num' => $res[0]['delivery_id'],
- 'phone' => '',
- 'from' => '',
- 'to' => '',
- 'resultv2' => '1'
- );
-
- $post_data = array();
- $post_data["customer"] = $customer;
- $post_data["param"] = json_encode($param);
- $sign = md5($post_data["param"] . $key . $post_data["customer"]);
- $post_data["sign"] = strtoupper($sign);
- $url = 'http://poll.kuaidi100.com/poll/query.do';
- $params = "";
- foreach ($post_data as $k => $v) {
- $params .= "$k=" . urlencode($v) . "&";
- }
- $post_data = substr($params, 0, -1);
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($ch);
- $data = str_replace("\"", '"', $result);
- $data = json_decode($data, true);
- if ($data['status'] != 200) {
- return app('json')->fail($data['message']);
- }
- switch ($data['state']) {
- case 0:
- $data['state'] = '在途';
- break;
- case 1:
- $data['state'] = '揽收';
- break;
- case 2:
- $data['state'] = '疑难';
- break;
- case 3:
- $data['state'] = '签收';
- break;
- case 4:
- $data['state'] = '退签';
- break;
- case 5:
- $data['state'] = '派件';
- break;
- case 6:
- $data['state'] = '退回';
- break;
- case 7:
- $data['state'] = '转单';
- break;
- case 10:
- $data['state'] = '待清关';
- break;
- case 11:
- $data['state'] = '清关中';
- break;
- case 12:
- $data['state'] = '已清关';
- break;
- case 13:
- $data['state'] = '清关异常';
- break;
- case 14:
- $data['state'] = '收件人拒签';
- break;
- default:
- $data['state'] = '未知';
- break;
- }
- unset($data['message']);
- unset($data['status']);
- unset($data['ischeck']);
- $data['com'] = $res[0]['delivery_name'];
- unset($data['condition']);
- return app('json')->success('ok', $data);
- }
-
- public function line(Request $request)
- {
- $line_num=sys_config('line_num');
- $find_line_num=Line::where('uid',$request->uid())->whereTime('add_time', 'today')->count();
- if($find_line_num>=$line_num) return app('json')->fail('当日参加排队次数已达上限');
-
-
- $id=line::createLevelOrder($request->uid());
- if($id){
- return app('json')->successful($id->toArray());
- }else{
- return app('json')->fail('排队失败');
- }
- }
-
- public function line_order(Request $request){
- list($type,$page,$limit) = UtilService::postMore([['type', ''],['page',1],['limit',20]], $request, true);
- $arr=Line::my_line($type,$page,$limit,$request->uid());
- return app('json')->successful($arr->toArray());
- }
-
- public function line_list(Request $request){
- list($page,$limit) = UtilService::postMore([['page',1],['limit',20]], $request, true);
- $info = $request->user()->toArray();
- $arr['max']=sys_config('line_num');
- $arr['low']=Line::where('uid',$request->uid())->whereTime('add_time','today')->count();
-
- $arr['suc_bo_pd']=sys_config('suc_bo_pd');
-
- $arr['del_wdc']=sys_config('del_wdc');
-
- $arr['invite_num_pd']=sys_config('invite_num_pd');
-
- $arr['wdc']=$info['wdc'];
-
- $arr['all_line_sum']=Line::where('uid',$request->uid())->count();
-
- $arr['now_line_sum']=Line::where('uid',$request->uid())->where('status',0)->count();
-
- $arr['over_line_sum']=Line::where('uid',$request->uid())->where('status',1)->count();
- $find=Line::where('status',1)->order('id desc')->page($page,$limit)->select();
- foreach($find as $key=>&$value){
- $value['key']=$key+1;
- $value['info']=User::where('uid',$value['uid'])->find();
- if($value['info']) $value['info']= $value['info']->toArray();
- $value['time']=date('Y-m-d h:i:s',$value['suc_time']);
- }
- $arr['info']=$find;
- return app('json')->successful($arr);
- }
-
- public function js_line(Request $request){
- list($order_id) = UtilService::postMore([['order_id', '']], $request, true);
- $arr=Line::js_line($order_id);
- if($arr){
- return app('json')->successful('成功');
- }else{
- return app('json')->fail('失败');
- }
- }
- }
|