BookingController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\booking;
  8. use app\modules\admin\controllers\BaseController;
  9. use app\modules\admin\models\booking\BookingForm;
  10. use app\models\Admin;
  11. use app\models\BookingOrderExt;
  12. use app\models\MdStaff;
  13. use app\models\Md;
  14. use app\utils\Notice\NoticeSend;
  15. class BookingController extends BaseController
  16. {
  17. public function actionCatListSelect()
  18. {
  19. $form = new BookingForm();
  20. $form->store_id = get_store_id();
  21. $res = $form->catListSelect();
  22. return $this->asJson($res);
  23. }
  24. public function actionCatList()
  25. {
  26. $form = new BookingForm();
  27. $form->name = get_params('name');
  28. $form->status = get_params('status', -1);
  29. $form->store_id = get_store_id();
  30. $res = $form->catList();
  31. return $this->asJson($res);
  32. }
  33. public function actionCatInfo()
  34. {
  35. $form = new BookingForm();
  36. $id = get_params('id', 0);
  37. $res = $form->catInfo($id);
  38. return $this->asJson($res);
  39. }
  40. public function actionCatSave()
  41. {
  42. $form = new BookingForm();
  43. $id = input_params('id', 0);
  44. $name = input_params('name', '');
  45. $pic_url = input_params('pic_url', '');
  46. $sort = input_params('sort', 1000);
  47. $is_show = input_params('is_show', 1);
  48. $form->store_id = get_store_id();
  49. $res = $form->catSave($id, $name, $pic_url, $sort, $is_show);
  50. return $this->asJson($res);
  51. }
  52. public function actionCatStatus()
  53. {
  54. $form = new BookingForm();
  55. $form->ids = input_params('ids', 0);
  56. $form->status = input_params('status', 1);
  57. $form->store_id = get_store_id();
  58. $res = $form->catStatus();
  59. return $this->asJson($res);
  60. }
  61. public function actionGoodsBookingTime()
  62. {
  63. $goods_id = input_params('goods_id', 0);
  64. $form = new \app\modules\client\models\v1\GoodsForm();
  65. $goodsBookingTime = $form->goodsBookingTime($goods_id);
  66. return $this->asJson([
  67. 'code' => 0,
  68. 'data' => $goodsBookingTime,
  69. ]);
  70. }
  71. public function actionBookingOrderList()
  72. {
  73. $form = new BookingForm();
  74. $params = all_params();
  75. $form->store_id = get_store_id();
  76. $res = $form->bookingOrderList($params);
  77. return $this->asJson($res);
  78. }
  79. public function actionBookingOrderCountByGoods()
  80. {
  81. $form = new BookingForm();
  82. $params = all_params();
  83. $form->store_id = get_store_id();
  84. $res = $form->bookingOrderCountByGoods($params);
  85. return $this->asJson($res);
  86. }
  87. public function actionBookingOrderCountByWorker()
  88. {
  89. $form = new BookingForm();
  90. $params = all_params();
  91. $form->store_id = get_store_id();
  92. $res = $form->bookingOrderCountByWorker($params);
  93. return $this->asJson($res);
  94. }
  95. public function actionAddBookingOrder()
  96. {
  97. $form = new BookingForm();
  98. $params = all_params();
  99. $form->store_id = get_store_id();
  100. $res = $form->bookingOrderSave($params);
  101. return $this->asJson($res);
  102. }
  103. // 服务人员列表
  104. public function actionWorkerList() {
  105. $md_id = get_md_id();
  106. $query = MdStaff::find()->alias('ms')->leftJoin(['md' => Md::tableName()], 'md.id=ms.md_id')->where(['ms.store_id' => get_store_id(), 'ms.is_delete' => 0, 'md.is_delete' => 0])->orderBy("ms.created_at desc, ms.updated_at desc");
  107. if ($md_id) {
  108. $query->andWhere(['ms.md_id' => $md_id]);
  109. }
  110. $list = $query->select('ms.id, ms.name')->asArray()->all();
  111. return $this->asJson([
  112. 'code' => 0,
  113. 'data' => $list,
  114. ]);
  115. }
  116. //分配订单
  117. public function actionOrderSetWorker()
  118. {
  119. $form = new BookingForm();
  120. $form->store_id = get_store_id();
  121. return $this->asJson($form->orderSetWorker(all_params()));
  122. }
  123. //确认收款
  124. public function actionOrderIsPay()
  125. {
  126. $form = new BookingForm();
  127. $form->store_id = get_store_id();
  128. return $this->asJson($form->orderIsPay(all_params()));
  129. }
  130. //确认收货
  131. public function actionOrderConfirm()
  132. {
  133. $form = new BookingForm();
  134. $form->store_id = get_store_id();
  135. return $this->asJson($form->orderConfirm(all_params()));
  136. }
  137. //订单操作
  138. public function actionOrderStatus()
  139. {
  140. $order_id = input_params('order_id');
  141. $type = input_params('type', 5);
  142. $cond = [
  143. 'and',
  144. ['order_id' => $order_id],
  145. ['store_id' => get_store_id()],
  146. ];
  147. $attr = [];
  148. if($type == 5){
  149. $cond = array_merge($cond, [
  150. ['<', 'status_ext', BookingOrderExt::STATUS_EXT_START],
  151. ]);
  152. $attr = [
  153. 'status_ext' => BookingOrderExt::STATUS_EXT_START,
  154. 'time_start_service' => time(),
  155. ];
  156. }
  157. if($type == 20){
  158. $cond = array_merge($cond, [
  159. ['<', 'status_ext', BookingOrderExt::STATUS_EXT_HAS_SYS_CONFIRM],
  160. ]);
  161. $attr = [
  162. 'status_ext' => BookingOrderExt::STATUS_EXT_HAS_SYS_CONFIRM,
  163. 'time_sys_confirm' => time(),
  164. ];
  165. }
  166. $orderExt = BookingOrderExt::find()->where($cond)->one();
  167. if(!$orderExt){
  168. return $this->asJson([
  169. 'code' => 1,
  170. 'msg' => '参数错误,或状态异常',
  171. ]);
  172. }
  173. $orderExt->setAttributes($attr, false);
  174. $save = $orderExt->save();
  175. if(!$save){
  176. return $this->asJson([
  177. 'code' => 1,
  178. 'msg' => '操作失败,' . array_shift($orderExt->getFirstErrors()),
  179. ]);
  180. }
  181. if($type == 20){
  182. NoticeSend::bookExamine($order_id);
  183. }
  184. return $this->asJson([
  185. 'code' => 0,
  186. 'msg' => 'success',
  187. ]);
  188. }
  189. }