MoveController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace addons\Happiness\agent\controllers;
  3. use addons\Happiness\common\enums\HappinessEnum;
  4. use addons\Happiness\common\models\HappinessMoveItem;
  5. use addons\Happiness\common\models\HappinessStore;
  6. use addons\Happiness\common\service\MoveService;
  7. use common\enums\StatusEnum;
  8. use Yii;
  9. use Exception;
  10. class MoveController extends BaseController
  11. {
  12. public function actionIndex()
  13. {
  14. if(Yii::$app->request->isAjax)
  15. {
  16. if(Yii::$app->request->isGet)
  17. {
  18. $data = Yii::$app->request->get();
  19. $where[]=['=','yo.status',StatusEnum::ENABLED];
  20. $where[]=['=','yo.mall_id',$this->mall_id];
  21. //or条件
  22. $where[] = ['or', ['in', 'st.city_id', $this->city_ids], ['in', 'st.district_id', $this->district_ids],['in', 'st.province_id', $this->province_ids]];
  23. if(!empty($data['keyword']))
  24. {
  25. $where[] = ['or', ['=', 'st.id', $data['keyword']], ['like', 'st.store_name',
  26. $data['keyword']]];
  27. }
  28. if($data['status']!='all')
  29. {
  30. $where[] = ['=', 'yo.order_status', $data['status']];
  31. }
  32. $with = [
  33. 'mallGood'=>function ($query) {
  34. $query->select('id,goods_name,cover_pic');
  35. },
  36. 'giveStore'=>function ($query) {
  37. $query->select('id,store_name,logo_img');
  38. }
  39. ];
  40. $join = [['LEFT JOIN',
  41. HappinessStore::tableName(). ' as st', "yo.store_id = st.id"]];
  42. $params = [
  43. 'select' => 'yo.*,st.city_id,st.district_id,st.store_name,st.logo_img',
  44. 'alias' => 'yo',
  45. 'where' =>$where,
  46. 'with' => $with,
  47. 'join' => $join,
  48. 'order' => 'id desc',
  49. ];
  50. $list=HappinessMoveItem::listPage($params);
  51. if($list===false)
  52. {
  53. return $this->error(HappinessMoveItem::getStaticError());
  54. }
  55. foreach ($list['list'] as &$item)
  56. {
  57. $item['goods_image'] = $item['mallGood']['cover_pic'];
  58. $item['goods_name'] = $item['mallGood']['goods_name'];
  59. $item['order_status_text'] = HappinessEnum::getMoveStatusMap()[$item['order_status']];
  60. }
  61. return $this->success('获取成功',$list);
  62. }
  63. }
  64. return $this->render('index');
  65. }
  66. public function actionMove()
  67. {
  68. if(Yii::$app->request->isAjax)
  69. {
  70. if(Yii::$app->request->isGet)
  71. {
  72. $id = Yii::$app->request->get('id');
  73. $model = HappinessMoveItem::find()->with(['goods.attr','goods.goods'])->where(['id'=>$id,
  74. 'status'=>StatusEnum::ENABLED])->asArray()->one();
  75. if(!$model)
  76. {
  77. return $this->error('数据不存在');
  78. }
  79. $goods_list=$model['goods'];
  80. //调货小店
  81. $where = ['and'];
  82. $where[] = ['or',
  83. ['in', 'city_id', $this->city_ids],
  84. ['in', 'district_id', $this->district_ids]
  85. ];
  86. $where[] = ['=', 'status', StatusEnum::ENABLED];
  87. $where[] = ['=', 'mall_id', $this->mall_id];
  88. $store_list = HappinessStore::find()
  89. ->select('id,store_name,logo_img')
  90. ->where($where)
  91. ->asArray()
  92. ->all();
  93. return $this->success('获取成功',compact('store_list','goods_list'));
  94. }
  95. if(Yii::$app->request->isPost)
  96. {
  97. $data = Yii::$app->request->post();
  98. if(empty($data))
  99. {
  100. return $this->error('参数错误');
  101. }
  102. $id=$data['id'];
  103. $has=HappinessMoveItem::find()->where(['id'=>$id])->one();
  104. if(!$has)
  105. {
  106. return $this->error('数据不存在');
  107. }
  108. if($has['order_status']!=0)
  109. {
  110. return $this->error('调货单已处理');
  111. }
  112. $store_id=$data['store_id'];
  113. $service=new MoveService(['mall_id'=>$this->mall_id,'store_id'=>$store_id,
  114. 'user_id'=>$this->admin->user_id]);
  115. $res=$service->auditMove($data);
  116. if($res===false)
  117. {
  118. return $this->error($service->getError());
  119. }
  120. if($data['audit_status']==0)
  121. {
  122. return $this->success('拒绝调货');
  123. }
  124. return $this->success('调货成功');
  125. }
  126. }
  127. }
  128. }