request->get(); $status = $get['status'] ?? 0; if (!empty($status)) { $where['status'] = $status; } $where['sjId'] = $this->sjId; if (isset($get['shopId'])) { $shopId = $get['shopId'] ?? 0; if (!empty($shopId)) { $where['shopId'] = $this->shopId; } } else { $where['shopId'] = $this->shopId; } $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']]]; } $name = $get['name'] ?? ''; if (!empty($name)) { if (preg_match("/^[a-zA-Z\s]+$/", $name)) { $where['customNamePy'] = ['like', $name]; } else { $where['customName'] = ['like', $name]; } } $respond = OrderClass::getOrderList($where); $respond['shop'] = $this->shop; $respond['shopExt'] = $this->shopExt; util::success($respond); } //商城下单操作 ssh 2021.1.14 public function actionCreateOrder() { $post = Yii::$app->request->post(); $shopId = $this->shopId; $customId = $post['customId'] ?? 0; $post['customId'] = $customId; //开单必须选客户 if (empty($customId)) { util::fail('请选择客户'); } $custom = CustomClass::getCustom($customId); if (empty($custom)) { util::fail('请选客户哦'); } CustomClass::valid($custom, $this->shopId); $post['ghsId'] = $custom['ghsId'] ?? 0; $post['customMobile'] = $custom['mobile'] ?? ''; $customName = $custom['name'] ?? ''; $post['customName'] = $customName; $post['customNamePy'] = $custom['py'] ?? ''; $post['customAvatar'] = $custom['shortSmallAvatar'] ?? ''; $post['shopAdminId'] = $this->shopAdminId; $post['province'] = $custom['province'] ?? ''; $post['city'] = $custom['city'] ?? ''; $post['dist'] = $custom['dist'] ?? ''; $post['address'] = $custom['address'] ?? ''; $post['floor'] = $custom['floor'] ?? ''; $post['fullAddress'] = $custom['fullAddress'] ?? ''; $post['showAddress'] = $custom['showAddress'] ?? ''; $shopAdmin = $this->shopAdmin->attributes; $post['shopAdminName'] = $shopAdmin['name'] ?? ''; $post['sjId'] = $this->sjId; $post['shopId'] = $shopId; $post['fromType'] = 1; $post['expressId'] = $post['expressId'] ?? 0; $post['sendCost'] = $post['sendCost'] ?? '0.00'; $post['payWay'] = dict::getDict('payWay', 'wxPay'); //PC端开单 if (isset($post['clearType'])) { $clearType = $post['clearType']; if ($clearType == OrderClass::CLEAR_DEBT) { $post['debt'] = OrderClass::DEBT_YES; $post['payWay'] = dict::getDict('payWay', 'debtPay'); } else { $post['debt'] = OrderClass::DEBT_NO; } } //PC端开单 if (isset($post['getType'])) { $getType = $post['getType']; //自取 if ($getType == 1) { $post['sendType'] = OrderClass::SEND_TYPE_NO; } else { //选择配送时,在发货时让商家自己再确认一下用什么方式 $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN; } } $productJson = $post['product'] ?? ''; if (empty($productJson)) { util::fail('请选择花材'); } $productList = json_decode($productJson, true); if (empty($productList)) { util::fail('请选择花材'); } $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { //判断花材有效性 ProductClass::valid($productList, $this->shopId); $post['product'] = $productList; $return = OrderService::createOrder($post, $custom); $transaction->commit(); util::success($return); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("下单失败原因:" . $e->getMessage()); util::fail('下单失败'); } } //延期支付 ssh 2021.1.19 public function actionDebt() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $info = OrderService::getOrderInfo($id); OrderClass::valid($info, $this->shopId); OrderClass::debt($info, $this->shop); util::complete(); } //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3 public function actionWxPay() { ini_set('date.timezone', 'Asia/Shanghai'); $post = Yii::$app->request->post(); $couponId = $post['couponId'] ?? 0; $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0; $order = OrderClass::getByOrderSn($orderSn); if (empty($order)) { util::fail('订单号无效'); } $id = $order['id']; //支付前验证订单有效性 if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) { util::fail('没有权限操作'); } $name = $order['orderName'] ?? '购买商品'; $totalFee = $order['actPrice']; //强制使用小程序的miniOpenId $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : ''; if (empty($openId)) { util::fail('没有找到openId'); } $capitalType = dict::getDict('capitalType', 'xhGhsOrder', '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['ghsHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 //$merchantExtend = $this->sjExtend->attributes; $merchantExtend = WxOpenClass::getGhsWxInfo(); if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //强制使用小程序的miniAppId $merchantExtend['wxAppId'] = $merchantExtend['miniAppId']; $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend); $newParams = json_decode($jsApiParameters, true); //微信不能修改价格 $current = date("Y-m-d H:i:s"); $updateData = ['deadline' => $current, 'modPrice' => 0]; OrderClass::updateById($id, $updateData); util::success($newParams); } //获取订单详情 ssh 2021.1.21 public function actionDetail() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $info = OrderService::getOrderInfo($id, true, true, true, false); OrderClass::valid($info, $this->shopId); //是否有云打印判断 $hasCloudPrint = 0; $shopExt = $this->shopExt; if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) { $hasCloudPrint = 1; } $info['hasCloudPrint'] = $hasCloudPrint; util::success($info); } //自取免发货流程处理 ssh 2021.1.22 public function actionWithoutSend() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $info = OrderService::getById($id, true); OrderClass::valid($info, $this->shopId); $purchaseId = $info->purchaseId; $purchase = PurchaseClass::getById($purchaseId, true); OrderService::withoutSend($info, $purchase); util::complete(); } //本店送 ssh 2021.1.24 public function actionSelfSend() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $info = OrderClass::getById($id, true); OrderClass::valid($info->attributes, $this->shopId); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { OrderClass::selfSend($info); $transaction->commit(); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("本店送操作报错:" . $exception->getMessage()); util::fail('操作失败'); } util::complete(); } //运费计算 ssh 2021.1.24 public function actionFreight() { //2021.3.28 接入达达 $get = Yii::$app->request->get(); $post = Yii::$app->request->post(); if (empty($get)) { $get = $post; } $orderId = $get['id'] ?? 0; //订单ID $customId = $get['customId'] ?? 0; if (empty($orderId)) { //自定义运费 //freight::getCost(); if (empty($customId)) { util::fail("请选择客户"); } $customInfo = CustomClass::getById($customId); if (empty($customInfo)) { util::fail('没有找到客户'); } $shop = $this->shop; //花材信息 $productJson = $get['product'] ?? ''; // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]'; if (empty($productJson)) { util::fail('请选择花材'); } $productList = json_decode($productJson, true); if (empty($productList)) { util::fail('请选择花材'); } $productList = ProductClass::mergeItemInfo($productList); $weight = 0; $price = 0; $productData = ProductClass::getProductMapData($productList); $bigNum = 0; foreach ($productList as $key => $val) { $productId = $val['productId']; $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']); $bigNum += $val['bigNum']; $weight = bcadd($w, $weight, 2); $ratio = $productData[$productId]['ratio'] ?? 0; //大小数量合并多少扎 $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio); //售卖价格 $itemPrice = $productData[$productId]['price'] ?? 0; //合计价格 $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2); } //没有经纬度的客户运费直接返回空 shish 20210612 if (empty($customInfo['lat']) || empty($customInfo['long'])) { util::success(['sedCost' => '']); } $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight); util::success(['sedCost' => $cost]); } $province = $get['province'] ?? ''; $city = $get['city'] ?? ''; $address = $get['address'] ?? ''; $floor = $get['floor'] ?? ''; $customName = $get['customName'] ?? ''; $customMobile = $get['customMobile'] ?? ''; $fullAddress = $province . $city . $address . $floor; $sendTime = $get['sendTime'] ?? ''; $lat = $get['lat'] ?? ''; $lng = $get['long'] ?? ''; if (empty($lat) || empty($lng) || empty($fullAddress)) { util::fail('请填写客户地址'); } ini_set('date.timezone', 'Asia/Shanghai'); if (!empty($sendTime)) { //配送时间不为空 // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约 $sendTimeInt = strtotime($sendTime); $now = time(); $diff = $sendTimeInt - $now; //因服务器写入时间,改为至少提前6分钟 if ($diff <= 360) { util::fail('配送时间至少提前6分钟'); } } else { //默认立即发送 $sendTime = 0; } //更新订单表 $info = OrderService::getOrderInfo($orderId); OrderClass::valid($info, $this->shopId); if ($sendTime) { $sendTime = date('Y-m-d H:i', strtotime($sendTime)); } else { $sendTime = '0000-00-00 00:00:00'; } $expressAddInfo = [ 'customName' => $customName, 'customMobile' => $customMobile, 'province' => $province, 'city' => $city, 'address' => $address, 'floor' => $floor, 'lat' => $lat, 'long' => $lng, 'sendTime' => $sendTime, ]; OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo); //计算运费 $info['province'] = $province; $info['city'] = $city; $info['address'] = $address; $info['floor'] = $floor; $info['fullAddress'] = $fullAddress; $info['lat'] = $lat; $info['long'] = $lng; $info['sendTime'] = $expressAddInfo['sendTime']; $res = DadaExpressServices::queryDeliverFee($info); util::success(['sedCost' => $res['fee']]); } //发快递和第三方配送 ssh 2021.1.24 public function actionThirdSend() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $info = OrderService::getById($id, true); OrderClass::valid($info->attributes, $this->shopId); if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) { util::fail('请填写客户地址'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $respond = OrderClass::thirdSend($info, $get); $transaction->commit(); util::success($respond); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("发快递操作报错:" . $exception->getMessage()); util::fail('操作失败' . $exception->getMessage()); } } //确认送达 ssh 2021.1.24 public function actionReach() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $info = OrderClass::getById($id, true); OrderClass::valid($info->attributes, $this->shopId); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { OrderService::reach($info); $transaction->commit(); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("送达操作报错:" . $exception->getMessage()); util::fail('操作失败'); } util::complete(); } //下单要用到的相关信息 ssh 2019.12.6 public function actionOrderRelate() { $regionTree = RegionService::tree(); $shop = $this->shop->attributes; $freight = ['first' => 5, 'add' => 2]; $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH'; $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop]; util::success($out); } //客户欠款的订单 ssh 2021.2.4 public function actionDebtList() { $id = Yii::$app->request->get('id', 0); $info = CustomClass::getCustom($id); CustomClass::valid($info, $this->shopId); $where = ['customId' => $id, 'debt' => 1]; $respond = OrderService::getDebtOrderList($where); $respond['customInfo'] = $info; util::success($respond); } //更新打印次数 public function actionAddPrintNum() { $id = Yii::$app->request->get('id', 0); $order = OrderClass::getById($id, true); OrderClass::valid($order, $this->shopId); $order->printNum += 1; $order->save(); util::complete(); } //打印订单 shish 20210714 public function actionCloudPrintOrder() { $id = Yii::$app->request->get('id', 0); $order = OrderClass::getById($id, true); OrderClass::valid($order, $this->shopId); //打印订单 OrderClass::onlinePrint($order); $order->printNum += 1; $order->save(); util::complete(); } }