request->get(); $query = xhOrder::find(); $merchantId = $this->merchantId; $query->where(['merchantId' => $merchantId]); $currentShopId = $this->admin['currentShopId']; $query->andWhere(['shopId' => $currentShopId]); if (isset($get['payStatus']) && $get['payStatus'] >= 0) { $query->andWhere(['payStatus' => $get['payStatus']]); } $content = ''; if (isset($get['content']) && !empty($get['content'])) { $content = $get['content']; if (stringUtil::isMobieNumber($content)) { $query->andWhere(['bookMobile' => $content]); } elseif (is_numeric($content)) { $query->andWhere(['id' => $content]); } else { $query->andWhere(['like', 'bookName', $content]); } } $query->orderBy('createTime desc'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); $reachPeriodName = configDict::getConfig('reachPeriodName'); $payStatusName = configDict::getConfig('payStatusName'); return $this->render('complete', ['models' => $models, 'payStatusName' => $payStatusName, 'reachPeriodName' => $reachPeriodName, 'pages' => $pages, 'content' => $content, 'merchant' => $this->merchant]); } public function actionUnInform() { $get = Yii::$app->request->get(); $query = xhOrder::find(); $merchantId = $this->merchantId; $query->where(['merchantId' => $merchantId]); $currentShopId = $this->admin['currentShopId']; $query->andWhere(['shopId' => $currentShopId]); if (isset($get['payStatus']) && $get['payStatus'] >= 0) { $query->andWhere(['payStatus' => $get['payStatus']]); } $content = ''; if (isset($get['content']) && !empty($get['content'])) { $content = $get['content']; if (stringUtil::isMobieNumber($content)) { $query->andWhere(['bookMobile' => $content]); } elseif (is_numeric($content)) { $query->andWhere(['id' => $content]); } else { $query->andWhere(['like', 'bookName', $content]); } } $query->orderBy('createTime desc'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); $reachPeriodName = configDict::getConfig('reachPeriodName'); $payStatusName = configDict::getConfig('payStatusName'); return $this->render('unInform', ['models' => $models, 'payStatusName' => $payStatusName, 'reachPeriodName' => $reachPeriodName, 'pages' => $pages, 'content' => $content, 'merchant' => $this->merchant]); } public function actionUnSend() { $get = Yii::$app->request->get(); $query = xhOrder::find(); $merchantId = $this->merchantId; $query->where(['merchantId' => $merchantId]); $currentShopId = $this->admin['currentShopId']; $query->andWhere(['shopId' => $currentShopId]); if (isset($get['payStatus']) && $get['payStatus'] >= 0) { $query->andWhere(['payStatus' => $get['payStatus']]); } $content = ''; if (isset($get['content']) && !empty($get['content'])) { $content = $get['content']; if (stringUtil::isMobieNumber($content)) { $query->andWhere(['bookMobile' => $content]); } elseif (is_numeric($content)) { $query->andWhere(['id' => $content]); } else { $query->andWhere(['like', 'bookName', $content]); } } $query->orderBy('createTime desc'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); $reachPeriodName = configDict::getConfig('reachPeriodName'); $payStatusName = configDict::getConfig('payStatusName'); return $this->render('unSend', ['models' => $models, 'payStatusName' => $payStatusName, 'reachPeriodName' => $reachPeriodName, 'pages' => $pages, 'content' => $content, 'merchant' => $this->merchant]); } public function actionUnPay() { $get = Yii::$app->request->get(); $query = xhOrder::find(); $merchantId = $this->merchantId; $query->where(['merchantId' => $merchantId]); $currentShopId = $this->admin['currentShopId']; $query->andWhere(['shopId' => $currentShopId]); if (isset($get['payStatus']) && $get['payStatus'] >= 0) { $query->andWhere(['payStatus' => $get['payStatus']]); } $content = ''; if (isset($get['content']) && !empty($get['content'])) { $content = $get['content']; if (stringUtil::isMobieNumber($content)) { $query->andWhere(['bookMobile' => $content]); } elseif (is_numeric($content)) { $query->andWhere(['id' => $content]); } else { $query->andWhere(['like', 'bookName', $content]); } } $query->orderBy('createTime desc'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); $reachPeriodName = configDict::getConfig('reachPeriodName'); $payStatusName = configDict::getConfig('payStatusName'); return $this->render('unPay', ['models' => $models, 'payStatusName' => $payStatusName, 'reachPeriodName' => $reachPeriodName, 'pages' => $pages, 'content' => $content, 'merchant' => $this->merchant]); } public function actionList() { $get = Yii::$app->request->get(); $query = xhOrder::find(); $merchantId = $this->merchantId; $query->where(['merchantId' => $merchantId]); $currentShopId = $this->admin['currentShopId']; $query->andWhere(['shopId' => $currentShopId]); if (isset($get['payStatus']) && $get['payStatus'] >= 0) { $query->andWhere(['payStatus' => $get['payStatus']]); } $content = ''; if (isset($get['content']) && !empty($get['content'])) { $content = $get['content']; if (stringUtil::isMobieNumber($content)) { $query->andWhere(['bookMobile' => $content]); } elseif (is_numeric($content)) { $query->andWhere(['id' => $content]); } else { $query->andWhere(['like', 'bookName', $content]); } } $query->orderBy('createTime desc'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]); $models = $query->offset($pages->offset)->orderBy('addTime desc')->limit($pages->limit)->asArray()->all(); $reachPeriodName = configDict::getConfig('reachPeriodName'); $payStatusName = configDict::getConfig('payStatusName'); $usageList = $this->usageList; $categoryList = $this->categoryList; return $this->render('list', ['models' => $models, 'payStatusName' => $payStatusName, 'reachPeriodName' => $reachPeriodName, 'pages' => $pages, 'content' => $content, 'merchant' => $this->merchant, 'usageList' => $usageList, 'categoryList' => $categoryList]); } /** * 网上订单明细 */ public function actionDetail() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $order = xhOrderService::getById($id); if (empty($order) || $order['merchantId'] != $this->merchantId) { util::stop('访问出错,请联系网站管理员'); } $goodsList = xhOrderGoods::getAllByCondition(['orderId' => $id]); foreach ($goodsList as $key => $good) { $goodsId = $good['goodsId']; $goodsData = xhGoodsService::getById($goodsId); if ($goodsData['goodsName'] != $good['title']) { $subTitle = $good['title']; $goodsList[$key]['title'] = $goodsData['goodsName']; $goodsList[$key]['subTitle'] = $subTitle; } } $reachPeriodName = configDict::getConfig('reachPeriodName');//送达时间点 上午 下午 晚上 $userId = 0; $userInfo = []; if (!empty($order['userId'])) { $userId = $order['userId']; $userInfo = xhUserService::getById($userId); } $payWayNameList = configDict::getConfig('payWayName'); $alipayWay = configDict::getConfig('payWay', 'alipay'); $alipayInfo = []; if ($order['payWay'] == $alipayWay) { $alipayId = $order['alipayId']; $merchantId = $order['merchantId']; $alipayInfo = xhUserAlipayService::getByIds($alipayId, $merchantId); } $sendStatusName = configDict::getConfig('sendStatusName'); return $this->render('detail', ['sendStatusName' => $sendStatusName, 'userInfo' => $userInfo, 'alipayWay' => $alipayWay, 'alipayInfo' => $alipayInfo, 'payWayNameList' => $payWayNameList, 'order' => $order, 'reachPeriodName' => $reachPeriodName, 'goodsList' => $goodsList, 'merchant' => $this->merchant]); } public function actionUpdatePayStatus() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $order = xhOrderService::getById($id); if (empty($order) || $order['merchantId'] != $this->merchantId) { util::failInfo('非法访问'); } $status = isset($get['status']) ? $get['status'] : 0; if ($order['payStatus'] == 0) { //util::failInfo('客户还没有付款'); $userId = $order['userId']; $user = xhUserService::getById($userId); if (empty($user)) { util::failInfo('客户信息出错-用户ID未保存'); } } xhOrderService::updateById($id, ['sendStatus' => $status]); if ($status == 2) {//已经送达,通知订花人 $userId = $order['userId']; $user = xhUserService::getById($userId); $openId = $user['openId']; $merchantId = $user['merchantId']; if (xhUserService::isSubscribe($userId)) { $allTM = xhTMessageService::getList($merchantId); $shortTempId = 'OPENTM201205968';//订单送达通知 if (isset($allTM[$shortTempId])) { $tempId = $allTM[$shortTempId]; $data = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['frontUrl'] . "/center/order-detail?id={$order['id']}&account={$this->merchantId}", "data" => [ "first" => ["value" => '您的订单已送达', "color" => "#173177"], "keyword1" => ["value" => (string)$order['id'], "color" => "#173177"], "keyword2" => ["value" => $order['receiveUserName'], "color" => "#173177"], "keyword3" => ["value" => '已送达', "color" => "#173177"], "remark" => ["value" => '感谢您惠顾,祝你生活愉快!', "color" => "#173177"]]]; weixinUtil::sendTaskInform($data, $this->merchant); } } } echo Json::encode(['code' => 'A0001', 'msg' => '操作成功', 'data' => []]); } /** * 订单修改 * @param $id */ public function actionEditOrder($id) { $orderData = xhOrderService::getById($id); if (empty($orderData)) { util::failInfo('此订单不存在'); } $orderData['reachTime'] = substr($orderData['reachTime'], 0, 10); util::successInfo('获取成功', 'A0001', $orderData); } /** * 保存订单修改 * @param $id */ public function actionSaveEditOrder() { $updateData = []; $post = Yii::$app->request->post(); $orderData = xhOrderService::getById($post['id']); if (empty($orderData)) { util::failInfo('此订单不存在'); } //已付款 或 微信中打开支付链接的,不可修改价格 $status = $orderData['actPrice'] != $post['consumeAmount'] ? true : false; if ($orderData['modPriceStatus'] == 1 && $status) { util::failInfo('订单已锁定,不能修改价格'); } else if ($orderData['payStatus'] == 1 && $status) { util::failInfo('订单已付款,不能修改价格'); } xhOrderService::formatPost($updateData, $post); $re = xhOrderService::updateById($post['id'], $updateData); if ($re['status']) { $msg = '保存成功'; } else { $msg = '表单数据未变更'; } util::successInfo($msg, 'A0001', $orderData); } /** * 打印订单 */ public function actionPrint() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $order = xhOrderService::getById($id); if (empty($order) || $order['merchantId'] != $this->merchantId) { echo '访问出错了,请联系网站管理员'; Yii::$app->end(); } $goodsList = xhOrderGoods::getAllByCondition(['orderId' => $id]); $list = []; foreach ($goodsList as $val) { $list[] = ['name' => $val['title'], 'num' => $val['num']]; } return $this->renderPartial('print', ['order' => $order, 'merchant' => $this->merchant, 'goodsList' => $list]); } /** * 更新打印状态 */ public function actionUpdatePrintStatus() { $get = Yii::$app->request->get(); $status = isset($get['status']) ? $get['status'] : 1; $id = isset($get['id']) ? $get['id'] : 0; $order = xhOrderService::getById($id); if (empty($order) || $order['merchantId'] != $this->merchantId) { echo Json::encode(['code' => 'A0002', 'data' => '', 'msg' => '出错了,请联系网站管理员']); Yii::$app->end(); } xhOrderService::updateById($id, ['printStatus' => $status]); echo Json::encode(['code' => 'A0001', 'data' => '', 'msg' => 'success']); } /** * 修改价格 */ public function actionModifyPrice() { $get = Yii::$app->request->get(); $actPrice = isset($get['actPrice']) ? $get['actPrice'] : 10000; $id = isset($get['id']) ? $get['id'] : 0; $order = xhOrderService::getById($id, $this->merchantId); /*if($order['merchantId'] != $this->merchantId){ util::failInfo('非法访问'); }*/ if ($order['modPriceStatus'] == 1) { util::failInfo('订单已锁定,不能修改价格'); } $prePrice = $order['actPrice']; xhOrderService::updateById($id, ['actPrice' => $actPrice]); $userId = $order['userId']; $user = xhUserService::getById($userId); if (empty($user)) { echo Json::encode(['code' => 'A0001', 'data' => '', 'msg' => "修改成功"]); exit(); } $openId = $user['openId']; $merchantId = $user['merchantId']; //价格修改通知 $allTM = xhTMessageService::getList($merchantId); $shortTempId = 'OPENTM401761342'; if (isset($allTM[$shortTempId])) { $tempId = $allTM[$shortTempId]; $data = [ "touser" => $openId, "template_id" => $tempId,//模板id,从公众平台后台取得 "url" => $this->frontUrl . "/center/order-detail?id={$order['id']}&account={$this->merchantId}", "data" => [ "first" => ["value" => '您好,你购买的商品价格已修改。', "color" => "#173177"], "keyword1" => ["value" => (string)$order['id'], "color" => "#173177"], "keyword2" => ["value" => $prePrice, "color" => "#173177"], "keyword3" => ["value" => number_format($actPrice, 2), "color" => "#173177"], "remark" => ["value" => '点此进行支付。', "color" => "#173177"]]]; weixinUtil::sendTaskInform($data, $this->merchant); } echo Json::encode(['code' => 'A0001', 'data' => '', 'msg' => "修改成功,已通知客户"]); } /** * 修改商品的配送编号 */ public function actionModifySendNum() { $get = Yii::$app->request->get(); $id = isset($get['id']) ? $get['id'] : 0; $num = isset($get['num']) ? $get['num'] : ''; $order = xhOrderService::getById($id); if ($order['merchantId'] != $this->merchantId) { util::failInfo('修改失败'); } xhOrderService::updateById($id, ['sendNum' => $num]); util::successInfo('修改成功'); } public function actionUserOrderList() { $get = Yii::$app->request->get(); $userId = isset($get['id']) ? $get['id'] : 0; $query = xhOrder::find(); $query->where(['userId' => $userId]); $countQuery = clone $query; $count = $countQuery->count(); $page = isset($get['page']) ? $get['page'] : 1; $pageSize = 20; $offset = ($page - 1) * $pageSize; $models = $query->offset($offset)->orderBy('createTime desc')->limit($pageSize)->asArray()->all(); $page = new page($count, $page, $pageSize); $paging = $page->fpage(); $reachPeriodName = configDict::getConfig('reachPeriodName'); $payStatusName = configDict::getConfig('payStatusName'); return $this->render('userOrderList', ['models' => $models, 'paging' => $paging, 'payStatusName' => $payStatusName, 'reachPeriodName' => $reachPeriodName]); } //设置订单的分类和用途 shish 2019.8.18 public function actionSetStyle() { $this->errorExportJson(); $get = Yii::$app->request->get(); $ret = OrderService::setOrderStyle($get); if ($ret == false) { util::sendFail($this->error->getError()); } util::sendSuccess(); } }