DeliveryStation.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\merchant\store\delivery;
  12. use app\common\repositories\system\serve\ServeOrderRepository;
  13. use crmeb\services\DeliverySevices;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. use app\common\repositories\delivery\DeliveryStationRepository;
  17. use app\validate\merchant\DeliveryStationValidate;
  18. use think\exception\ValidateException;
  19. class DeliveryStation extends BaseController
  20. {
  21. protected $repository;
  22. public function __construct(App $app, DeliveryStationRepository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. public function lst()
  28. {
  29. [$page, $limit] = $this->getPage();
  30. $where = $this->request->params(['keyword','station_name','status','type','date']);
  31. $where['mer_id'] = $this->request->merId();
  32. $data = $this->repository->merList($where, $page, $limit);
  33. return app('json')->success($data);
  34. }
  35. public function getTypeList()
  36. {
  37. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  38. [$page, $limit] = $this->getPage();
  39. $where = $this->request->params(['keyword','station_name']);
  40. $where['mer_id'] = $this->request->merId();
  41. $where['type'] = systemConfig('delivery_type');
  42. $where['status'] = 1;
  43. $data = $this->repository->merList($where, $page, $limit);
  44. return app('json')->success($data);
  45. }
  46. public function detail($id)
  47. {
  48. $data = $this->repository->detail($id,$this->request->merId());
  49. return app('json')->success($data);
  50. }
  51. public function create()
  52. {
  53. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  54. $data = $this->checkParams();
  55. $data['mer_id'] = $this->request->merId();
  56. $this->repository->save($data);
  57. return app('json')->success('添加成功');
  58. }
  59. public function update($id)
  60. {
  61. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  62. $data = $this->checkParams();
  63. $this->repository->edit($id, $this->request->merId(), $data);
  64. return app('json')->success('编辑成功');
  65. }
  66. public function delete($id)
  67. {
  68. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  69. $this->repository->destory($id, $this->request->merId());
  70. return app('json')->success('删除成功');
  71. }
  72. public function switchWithStatus($id)
  73. {
  74. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  75. $status = $this->request->param('status') == 1 ? 1 : 0;
  76. $this->repository->update($id,['status' => $status]);
  77. return app('json')->success('修改成功');
  78. }
  79. public function markForm($id)
  80. {
  81. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  82. return app('json')->success(formToData($this->repository->markForm($id, $this->request->merId())));
  83. }
  84. public function mark($id)
  85. {
  86. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  87. $data = $this->request->params(['mark']);
  88. $this->repository->update($id, $data);
  89. return app('json')->success('备注成功');
  90. }
  91. public function checkParams()
  92. {
  93. $data = $this->request->params([
  94. 'station_name',
  95. 'business',
  96. 'station_address',
  97. 'lng',
  98. 'lat',
  99. 'contact_name',
  100. 'phone',
  101. 'username',
  102. 'password',
  103. ['status',1],
  104. 'city_name',
  105. ]);
  106. $make = app()->make(DeliveryStationValidate::class);
  107. $data['type'] = systemConfig('delivery_type');
  108. if ($data['type'] == DeliverySevices::DELIVERY_TYPE_DADA) {
  109. $make->scene('dada')->check($data);
  110. } else {
  111. $make->check($data);
  112. }
  113. return $data;
  114. }
  115. public function getBusiness()
  116. {
  117. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  118. $data = $this->repository->getBusiness();
  119. return app('json')->success($data);
  120. }
  121. public function options()
  122. {
  123. $where = [
  124. 'status' => 1,
  125. 'mer_id' => $this->request->merId(),
  126. 'type' => systemConfig('delivery_type'),
  127. ];
  128. return app('json')->success($this->repository->getOptions($where));
  129. }
  130. public function select()
  131. {
  132. $where = [
  133. 'mer_id' => $this->request->merId(),
  134. ];
  135. return app('json')->success($this->repository->getOptions($where));
  136. }
  137. public function getCityLst()
  138. {
  139. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  140. return app('json')->success($this->repository->getCityLst());
  141. }
  142. /**
  143. * TODO 充值记录
  144. * @author Qinii
  145. * @day 2/18/22
  146. */
  147. public function payLst()
  148. {
  149. [$page, $limit] = $this->getPage();
  150. $where = [
  151. 'type' => 20,
  152. 'mer_id' => $this->request->merId(),
  153. 'date' => $this->request->param('date'),
  154. ];
  155. $data = app()->make(ServeOrderRepository::class)->getList($where, $page, $limit);
  156. $data['delivery_balance'] = $this->request->merchant()->delivery_balance;
  157. return app('json')->success($data);
  158. }
  159. public function getQrcode()
  160. {
  161. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  162. $data['pay_type'] = 1;
  163. $data['price'] = $this->request->param('price',10);
  164. if (!is_numeric($data['price']) || $data['price'] <= 0 )
  165. return app('json')->fail('支付金额不正确');
  166. $res = app()->make(ServeOrderRepository::class)->QrCode($this->request->merId(), 'delivery', $data);
  167. $res['delivery_balance'] = $this->request->merchant()->delivery_balance;
  168. return app('json')->success($res);
  169. }
  170. }