| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- namespace platform\controllers;
- use common\services\xhMerchantService;
- use common\components\configDict;
- use Yii;
- use yii\data\Pagination;
- use yii\helpers\Json;
- use common\models\xhOrder;
- use common\models\xhOrderGoods;
- use common\components\util;
- use common\components\stringUtil;
- use common\components\weixinUtil;
- use common\services\xhOrderService;
- use common\services\xhGoodsService;
- use common\services\xhTMessageService;
- use common\services\xhUserService;
- use common\services\xhUserAlipayService;
- use common\services\xhUserAssetService;
- use common\services\xhUserUniteService;
- use common\services\xhUserIntegralService;
- use common\services\xhMerchantCapitalService;
- use common\components\page;
- class OrderController extends PlatformController
- {
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $query = xhOrder::find();
- 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('list',['models' => $models,'payStatusName'=>$payStatusName,'reachPeriodName'=>$reachPeriodName,'pages' => $pages,'content' => $content]);
- }
- /**
- * 网上订单明细
- */
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $order = xhOrderService::getById($id);
- $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);
- }
- $merchantId = $order['merchantId'];
- $payWayNameList = configDict::getConfig('payWayName');
- $alipayWay = configDict::getConfig('payWay','alipay');
- $alipayInfo = [];
- if($order['payWay'] == $alipayWay){
- $alipayId = $order['alipayId'];
- $alipayInfo = xhUserAlipayService::getByIds($alipayId,$merchantId);
- }
- $merchant = xhMerchantService::getById($merchantId);
- return $this->render('detail',['userInfo'=>$userInfo,'alipayWay'=>$alipayWay,'alipayInfo'=>$alipayInfo,'payWayNameList'=>$payWayNameList,'order' => $order,'reachPeriodName'=>$reachPeriodName,'goodsList' => $goodsList,'merchant' => $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';//订单送达通知
- $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 == 1){
- $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';
- $tempId = $allTM[$shortTempId];
- $data = [
- "touser" => $openId,
- "template_id" => $tempId,//模板id,从公众平台后台取得
- "url" => $this->frontUrl."/center/order-detail?id={$order['id']}&account={$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;
- $user = xhUserService::getById($userId,$this->merchantId);
- $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]);
- }
- }
|