| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- <?php
- namespace hd\controllers;
- use biz\sj\services\MerchantAssetService;
- use biz\sj\services\MerchantExtendService;
- use biz\sj\services\MerchantService;
- use bizGhs\product\classes\ProductClass;
- use bizHd\custom\classes\CustomClass;
- use bizHd\merchant\services\ShopService;
- use bizHd\order\classes\OrderClass;
- use bizHd\order\classes\OrderSendClass;
- use bizHd\order\services\OrderService;
- use bizHd\saas\services\RegionService;
- use bizHd\user\services\UserService;
- use bizGhs\order\classes\OrderItemClass;
- use common\components\dict;
- use common\components\dateUtil;
- use common\services\xhPayToolService;
- use Yii;
- use common\components\util;
- use common\components\stringUtil;
- use bizHd\goods\services\GoodsService;
- use bizHd\merchant\services\ExpressService;
- use bizHd\order\services\OrderGoodsService;
- use bizHd\promote\services\CouponService;
- use common\components\httpUtil;
- class OrderController extends BaseController
- {
- public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
- //开单操作 ssh 2019.12.3
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
- $orderType = $post['orderType'] ?? 1;
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['payWay'] = $this->isWx == true ? 0 : 1;
- $now = time();
- $expireTime = $now + 1800;//订单30分钟后过期
- $post['deadline'] = $expireTime;
- $post['fromType'] = 1;//商城
- $customId = $post['customId'] ?? 0;
- if (!empty($customId)) {
- $customInfo = CustomClass::getCustomInfo($customId);
- CustomClass::valid($customInfo, $this->shopId);
- $post['customId'] = $customId;
- }
- //门店订单
- $post['store'] = 1;
- //员工信息
- $shopAdmin = $this->shopAdmin->attributes;
- $shopAdminName = $shopAdmin['name'] ?? '';
- $post['shopAdminName'] = $shopAdminName;
- $post['shopAdminId'] = $this->shopAdminId;
- $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
- if ($orderType == 1) {
- //$orderType = 1 成品订单
- $goodsInfo = $post['goodsInfo'] ?? '';
- $goodsInfoArr = json_decode($goodsInfo, true);
- if (empty($goodsInfoArr)) {
- util::fail('请选择商品');
- }
- //总的商品金额
- $totalGoodsPrice = 0;
- $orderGoods = [];
- foreach ($goodsInfoArr as $key => $currentGoods) {
- $currentGoodsId = $currentGoods['goodsId'];
- $currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
- if (empty($currentGoodsInfo)) {
- util::fail('没有找到商品');
- }
- $goodsStyleId = $currentGoods['goodsStyleId'];
- $goodsNum = $currentGoods['goodsNum'];
- //计算总金额
- $unitPrice = $currentGoodsInfo['price'];
- $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
- if (!empty($goodsStyleId)) {
- if (empty($goodsStyleList)) {
- util::fail('商品款式没有找到');
- }
- $styleIdList = array_keys(array_column($goodsStyleList, null, "id"));
- if (in_array($goodsStyleId, $styleIdList) == false) {
- util::fail('商品款式没有找到!');
- }
- $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
- }
- $goodsPrice = $unitPrice * $goodsNum;
- $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
- $orderGoods[] = [
- 'goodsId' => $currentGoodsId,
- 'userId' => $this->adminId,
- 'sjId' => $this->sjId,
- 'title' => $currentGoodsInfo['goodsName'],
- 'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
- 'unitPrice' => $unitPrice,
- 'num' => $goodsNum,
- 'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
- 'goodsStyleId' => $goodsStyleId,
- 'createTime' => date("Y-m-d H:i:s"),
- ];
- }
- $user = $this->custom;
- $post['bookName'] = isset($user['name']) ? $user['name'] : '';
- $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
- $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
- $post['bookMobile'] = $bookMobile;
- //计算运费
- $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
- $sendCost = 0;
- //按距离计算运费并且客户要求送的
- //运费计算方式
- $freightType = 0;
- if ($freightType == 0 && $needSend == 1) {
- //$lat = $post['latitude']??'';//收货人纬度
- //$lng = $post['longitude']??'';//收货人经度
- //$respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
- //$sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
- }
- $post['sendCost'] = $sendCost;
- $prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
- //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
- $sourceType = $this->isWx ? 0 : 1;
- if (httpUtil::isMiniProgram()) {
- $sourceType = 2;
- }
- $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
- $actPrice = $discountData['price'];
- $post['discountType'] = $discountData['discountType'];
- $post['discountAmount'] = $discountData['discountAmount'];
- $post['prePrice'] = $prePrice;
- $post['actPrice'] = $actPrice;
- $order = OrderClass::addOrder($post);
- $orderId = $order['id'];
- $orderSn = $order['orderSn'];
- foreach ($orderGoods as $key => $val) {
- $val['orderId'] = $orderId;
- $val['orderSn'] = $orderSn;
- OrderGoodsService::add($val);//创建订单商品列表
- }
- } else {
- //$orderType = 2 花材订单 组合开单
- $productData = $post['product'] ?? '';
- $product = json_decode($productData, true);
- if (empty($product)) {
- util::fail('请选择花材');
- }
- $actPrice = $post['packingFee']??0; //包装费
- $orderProduct = [];
- $productInfo = ProductClass::formatProductInfo($product);
- $actPrice = bcadd($actPrice,$productInfo['price'],2);
- foreach ($product as $key => $val) {
- $productId = $val['productId'];
- $bigNum = $val['bigNum'];
- $smallNum = $val['smallNum'];
- $orderProduct[] = [
- 'productId' => $productId,
- 'bigNum' => $bigNum,
- 'smallNum' => $smallNum,
- ];
- //减库存
- ProductClass::decreaseStock($productId, $bigNum, $smallNum);
- }
- $post['prePrice'] = $actPrice;
- $post['actPrice'] = $actPrice;
- $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
- $order = OrderClass::addOrder($post);
- $orderId = $order['id'];
- $orderSn = $order['orderSn'];
- foreach ($orderProduct as $key => $val) {
- $val['orderSn'] = $orderSn;
- OrderItemClass::add($val);
- }
- }
- $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
- OrderClass::staffKdPay($payWay, $orderSn);
- util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
- }
- //下单要用到的相关信息 ssh 2019.12.6
- public function actionOrderRelate()
- {
- $regionTree = RegionService::tree();
- $shop = $this->shop->attributes;
- $freight = MerchantExtendService::getFreight($this->sjExtend);
- $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
- $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
- util::success($out);
- }
- //余额支付 ssh 2019.12.6
- public function actionBalancePay()
- {
- $post = Yii::$app->request->post();
- $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
- $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
- //验证优惠券是否还有效
- if (!empty($couponId)) {
- CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
- }
- $order = OrderService::getByOrderSn($orderSn);
- $userId = $this->adminId;
- $user = UserService::getUserInfo($userId);
- //验证支付密码是否正确
- UserService::validPayPassword($payPassword, $user);
- //支付前验证订单有效性
- OrderService::checkBeforePay($order, $this->adminId);
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $totalFee = $order['prePrice'];
- $sourceType = 0;
- $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
- $actPrice = $discountData['price'];
- $callbackParams = [];
- $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
- $balance = isset($respond['balance']) ? $respond['balance'] : 0;
- util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
- }
- //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
- public function actionWxPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $post = Yii::$app->request->post();
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
- $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
- $order = OrderService::getByOrderSn($orderSn);
- $orderId = $order['id'];
- //验证优惠券是否还有效
- if (!empty($couponId)) {
- CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
- }
- //支付前验证订单有效性
- OrderService::checkBeforePay($order, $this->adminId);
- $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
- $totalFee = $order['actPrice'];
- //小程序使用miniOpenId
- if (httpUtil::isMiniProgram()) {
- $openId = $this->user['miniOpenId'];
- } else {
- $openId = $this->user['openId'];
- }
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
- $wxPayType = 0;
- if (httpUtil::isMiniProgram()) {
- $wxPayType = 1;
- }
- $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
- //订单30分钟后过期
- $now = time();
- $expireTime = $now + 1800;
- $wx = Yii::getAlias("@vendor/weixin");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.JsApiPay.php');
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($name);
- $input->SetOut_trade_no($orderSn);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetTime_start(date("YmdHis", $now));
- $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
- $input->SetTime_expire(date("YmdHis", $expireTime));
- $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("JSAPI");
- //花卉宝代为申请的微信支付
- $merchantExtend = $this->sjExtend->attributes;
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //小程序使用miniAppId
- if (httpUtil::isMiniProgram()) {
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
- }
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
- $newParams = json_decode($jsApiParameters, true);
- //已请求微信不能修改价格
- $updateData = [];
- $updateData['modPrice'] = 0;
- if (empty($order['deadline'])) {
- $updateData['deadline'] = $expireTime;
- }
- OrderService::updateById($orderId, $updateData);
- util::success($newParams);
- }
- //快捷付款订单
- public function actionFastPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $post = Yii::$app->request->post();
- $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
- $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
- //验证门店是否有效
- $shopInfo = ShopService::getById($shopId);
- ShopService::valid($shopInfo, $this->sjId);
- $post['shopId'] = $shopId;
- //默认门店订单
- $store = isset($post['store']) ? $post['store'] : 1;
- $post['store'] = $store;
- //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
- $sourceType = $this->isWx ? 0 : 1;
- if (httpUtil::isMiniProgram()) {
- $sourceType = 2;
- }
- $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
- //兼容旧系统sourceType=3表示朋友圈来源
- $fromType = $sourceType == 3 ? 2 : 0;
- $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
- $post['userId'] = $this->adminId;
- $custom = $this->custom;
- $post['bookName'] = $custom['userName'] ?? '';
- $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
- $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
- $post['bookMobile'] = $bookMobile;
- $prePrice = round($post['prePrice'], 2);
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
- $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
- $actPrice = $discountData['price'];
- $post['discountType'] = $discountData['discountType'];
- $post['discountAmount'] = $discountData['discountAmount'];
- $post['actPrice'] = $actPrice;
- $post['payStyle'] = 0;
- $post['sjId'] = $this->sjId;
- $now = time();
- $expireTime = $now + 300;//订单5分钟后过期
- $post['createTime'] = date("Y-m-d H:i:s", $now);
- $post['deadline'] = $expireTime;
- if ($actPrice <= 0) {
- util::fail('请填写正确的金额');
- }
- //微信支付订单提交不能修改价格
- $post['modPrice'] = $this->isWx ? 0 : 1;
- $post['sourceType'] = $sourceType;
- $post['goodsNum'] = 1;
- $post['fromType'] = $fromType;
- $order = OrderService::addOrder($post);
- $orderId = $order['id'];
- $orderSn = $order['orderSn'];
- $sjId = $this->sjId;
- if ($payWay == 0) {
- $orderId = $order['id'];
- $name = '购买商品';
- $totalFee = $actPrice;
- $user = UserService::getById($this->adminId);
- $openId = isset($user['openId']) ? $user['openId'] : 0;
- if (httpUtil::isMiniProgram()) {
- //小程序使用miniOpenId
- $openId = $user['miniOpenId'];
- }
- if (empty($openId)) {
- util::fail('没有找到客户的openId');
- }
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
- $wxPayType = 0;
- if (httpUtil::isMiniProgram()) {
- $wxPayType = 1;
- }
- $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
- $wx = Yii::getAlias("@vendor/weixin");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.JsApiPay.php');
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($name);
- $input->SetOut_trade_no($orderSn);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetTime_start(date("YmdHis", $now));
- $input->SetAttach($attach);
- //设置订单有效期5分钟
- $input->SetTime_expire(date("YmdHis", $expireTime));
- $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("JSAPI");
- //花卉宝代为申请的微信支付
- $merchantExtend = $this->sjExtend->attributes;
- if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //小程序使用miniAppId
- if (httpUtil::isMiniProgram()) {
- $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
- }
- Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
- $newParams = json_decode($jsApiParameters, true);
- $newParams['orderId'] = $orderId;
- util::success($newParams);
- } elseif ($payWay == 1) {
- $extend = MerchantExtendService::getByMerchantId($sjId);
- if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
- util::fail('支付宝付款即将开通...');
- }
- $config = [
- //应用ID,您的APPID。
- 'app_id' => $extend['alipayPId'],
- //商户私钥,您的原始格式RSA私钥
- 'merchant_private_key' => $extend['alipayKey'],
- //异步通知地址
- 'notify_url' => Yii::$app->params['mallHost'] . "/notice/ali-callback",
- //同步跳转
- 'return_url' => "",
- //编码格式
- 'charset' => "UTF-8",
- //签名方式
- 'sign_type' => "RSA2",
- //支付宝网关
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
- //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
- 'alipay_public_key' => $extend['alipayPublicKey'],
- ];
- Yii::info(json_encode($config) . ' aplipay config');
- $alipayWap = Yii::getAlias("@vendor/alipayWap");
- require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
- require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
- $totalFee = $order['actPrice'];
- $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
- $subject = '购买商品';//订单名称,必填
- $total_amount = $totalFee;//付款金额,必填
- $body = '';//商品描述,可空
- $timeout_express = "1m";//超时时间
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
- $passBackParams = urlencode($passBackParams);
- $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
- $payRequestBuilder->setBody($body);
- $payRequestBuilder->setSubject($subject);
- $payRequestBuilder->setOutTradeNo($out_trade_no);
- $payRequestBuilder->setTotalAmount($total_amount);
- $payRequestBuilder->setTimeExpress($timeout_express);
- //在异步通知时将该参数原样返回
- $payRequestBuilder->setPassbackParams($passBackParams);
- //同步通知
- $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
- //异步通知
- $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
- $payResponse = new \AlipayTradeService($config);
- $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
- //直接将支付宝的html返回给前端
- echo $result;
- } elseif ($payWay == 2) {
- //余额支付,验证支付密码是否正确
- $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
- $user = UserService::getUserInfo($this->adminId);
- UserService::validPayPassword($payPassword, $user);
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $callbackParams = [];
- $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
- $balance = isset($respond['balance']) ? $respond['balance'] : 0;
- util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
- } else {
- util::fail('无效的支付方式');
- }
- }
- //订单评价
- public function actionComment()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'];
- $order = OrderService::getById($id);
- OrderService::valid($order, $this->shopId);
- if ($order['grade'] > 0) {
- util::fail('您已经评过了');
- }
- OrderService::comment($post);
- util::complete('提交成功');
- }
- //订单详情 ssh 2019.12.16
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $orderSn = Yii::$app->request->get('orderSn', '');
- $detail = [];
- if (!empty($id)) {
- $detail = OrderService::getOrderById($id);
- }
- if (!empty($orderSn)) {
- $detail = OrderService::getOrderBySn($orderSn);
- }
- OrderService::valid($detail, $this->shopId);
- util::success($detail);
- }
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $search = isset($get['search']) ? $get['search'] : '';
- $where = [];
- $where['shopId'] = $this->shopId;
- $status = $get['status'] ?? 0;
- if (!empty($status)) {
- $where['status'] = $get['status'];
- }
- if (!empty($search)) {
- if (stringUtil::isMobile($search)) {
- $where['bookMobile'] = $search;
- } else {
- $where['orderSn'] = $search;
- }
- }
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $list = OrderService::getOrderList($where);
- $list['shop'] = $this->shop->attributes;
- util::success($list);
- }
- //订单归类 ssh 2019.12.17
- public function actionClassify()
- {
- $post = Yii::$app->request->post();
- $id = isset($post['id']) ? $post['id'] : 0;
- $order = OrderService::getById($id);
- OrderService::valid($order, $this->shopId);
- $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
- $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
- OrderService::classify($id, $categoryId, $usageId);
- util::complete();
- }
- //更新配送单 ssh 2019.12.17
- public function actionUpdateSheet()
- {
- $post = Yii::$app->request->post();
- $id = isset($post['id']) ? $post['id'] : 0;
- unset($post['id']);
- $order = OrderService::getById($id);
- OrderService::valid($order, $this->shopId);
- OrderService::updateSheet($order, $post);
- util::complete('提交成功');
- }
- //商家收款与发货 ssh 2019.12.18
- public function actionGathering()
- {
- $post = Yii::$app->request->post();
- $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
- $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
- $userId = isset($post['userId']) ? $post['userId'] : 0;
- $userInfo = UserService::getById($userId);
- if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
- util::fail('您选择的客户无效');
- }
- if ($price <= 0) {
- util::fail('请输入金额');
- }
- $post['prePrice'] = $price;
- $post['actPrice'] = $price;
- $post['payWay'] = $payWay;
- $post['sourceType'] = 1;
- $post['userId'] = $userId;
- $post['goodsNum'] = 1;
- $post['orderName'] = '商品';
- $shopId = MerchantService::getDefaultShopId($this->sj);
- $post['shopId'] = $shopId;
- $order = OrderService::addOrder($post);
- $id = $order['id'];
- $orderSn = $order['orderSn'];
- //流水类型列表
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $callbackParams = [];
- switch ($payWay) {
- case 0:
- xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
- break;
- case 1:
- xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
- break;
- case 2:
- xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
- break;
- default:
- util::fail('无效支付方式');
- }
- util::success($order);
- }
- //免发货管理 ssh 2020.1.6
- public function actionWithoutSend()
- {
- $id = Yii::$app->request->get('id');
- $order = OrderService::getById($id);
- OrderService::valid($order, $this->shopId);
- //配送流程变更
- $currentFlow = OrderSendClass::withoutSend($order);
- util::success(['currentFlow' => $currentFlow]);
- }
- //修改价格 ssh 2020.1.6
- public function actionUpdatePrice()
- {
- $id = Yii::$app->request->get('id');
- $price = Yii::$app->request->get('price', 1);
- $order = OrderService::getById($id);
- OrderService::valid($order, $this->shopId);
- if (isset($order['modPrice']) && $order['modPrice'] == 0) {
- util::fail('已发起支付,不能修改价格');
- }
- OrderService::updateById($id, ['actPrice' => $price]);
- util::complete('修改成功');
- }
- //配送单 ssh 2020.2.29
- public function actionGetDeliverDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $order = OrderService::getById($id);
- OrderService::valid($order, $this->shopId);
- $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
- $reachPeriodId = $order['reachPeriod'];
- $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
- $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
- $shopId = $order['shopId'];
- $telephone = '';
- if (!empty($shopId)) {
- $shop = ShopService::getById($shopId);
- }
- $telephone = isset($shop['telephone']) ? $shop['telephone'] : '';
- $bookName = isset($order['bookName']) ? $order['bookName'] : '';
- $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
- if (isset($order['anonymity']) && $order['anonymity'] == 1) {
- $bookName = '--';
- $bookMobile = '--';
- }
- $data = [
- 'reachDate' => $reachDate . ' ' . $reachPeriod,
- 'orderSn' => $order['orderSn'],
- 'receiveUserName' => $order['receiveUserName'],
- 'receiveMobile' => $order['receiveMobile'],
- 'fullAddress' => $order['address'] . $order['floor'] . "(" . $order['fullAddress'] . ")",
- 'cardInfo' => $order['cardInfo'],
- 'bookMobile' => $bookMobile,
- 'bookName' => $bookName,
- 'remark' => $order['remark'],
- 'sendNum' => $order['sendNum'],
- 'telephone' => 13600903070,
- 'printTime' => '',
- 'img' => '',
- ];
- util::success($data);
- }
- //运费计算 linqh 2021.4.12 暂反回固定
- public function actionFreight()
- {
- util::success(['sedCost' => 10]);
- }
- }
|