Apply.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\controller\members;
  13. use app\common\enum\member\AuditStatus;
  14. use app\store\controller\Controller;
  15. use app\store\controller\Goods;
  16. use app\store\model\Goods as GoodsModel;
  17. use app\store\model\member\Apply as ApplyModel;
  18. use app\store\model\member\MemberGoods as MemberGoodsModel;
  19. /**
  20. * 会员价商品管理
  21. * Class Refund
  22. * @package app\store\controller\member
  23. */
  24. class Apply extends Controller
  25. {
  26. /**
  27. * 列表
  28. * @return array
  29. * @throws \think\db\exception\DbException
  30. * @author: zjwhust
  31. * @Time: 2022/5/25 14:56
  32. */
  33. public function list()
  34. {
  35. $model = new ApplyModel;
  36. $list = $model->getList($this->request->param());
  37. return $this->renderSuccess(compact('list'));
  38. }
  39. /**
  40. * 详情
  41. * @param int $id
  42. * @return array;
  43. * @author: zjwhust
  44. * @Time: 2022/5/25 14:58
  45. */
  46. public function detail(int $id){
  47. $detail = ApplyModel::detail($id,['applyGoods'=>['goods']]);
  48. return $this->renderSuccess(compact('detail'));
  49. }
  50. /**
  51. * 新增
  52. * @return array
  53. * @author: zjwhust
  54. * @Time: 2022/5/25 14:56
  55. */
  56. public function add()
  57. {
  58. $model = new ApplyModel;
  59. $postData = $this->postForm();
  60. $postData['number'] = 'HYJ'.date('YmdHis').rand(100,999);
  61. $postData['admin_name'] = $postData['audit_user'] = $this->store['user']['real_name']?:'';
  62. $postData['admin_id'] = $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:'';
  63. if(!$model->add($postData)){
  64. return $this->renderError($model->getError() ?: '新增失败');
  65. }
  66. return $this->renderSuccess([], '新增成功');
  67. }
  68. /**
  69. * 获取新增会员价商品时的弹窗列表
  70. * @return array
  71. * @throws \think\db\exception\DbException
  72. * @author: zjwhust
  73. * @Time: 2022/5/27 16:50
  74. */
  75. public function addGoodsList(){
  76. $memberGoodsIds = (new MemberGoodsModel())->goodIds();//获取会员价商品ID集合
  77. $applyGoodsIds = (new ApplyModel())->goodIds(); //获取会员价商品审核中的商品ID集合
  78. $goodIds = array_unique(array_merge($memberGoodsIds,$applyGoodsIds));
  79. // 获取列表记录
  80. $model = new GoodsModel;
  81. $params = $this->request->param();
  82. $params['sortType'] = 'create_time';
  83. $params['listType'] = 'on_sale';
  84. $params['not_goods_id_arr'] = $goodIds;
  85. $list = $model->getList($params);
  86. return $this->renderSuccess(compact('list'));
  87. }
  88. /**
  89. * 获取编辑会员价商品时的弹窗列表
  90. * @return array
  91. * @throws \think\db\exception\DbException
  92. * @author: zjwhust
  93. * @Time: 2022/5/27 16:55
  94. */
  95. public function editGoodsList(){
  96. $memberGoodsIds = (new MemberGoodsModel())->goodIds();//获取会员价商品ID集合
  97. $applyGoodsIds = (new ApplyModel())->goodIds(); //获取会员价商品审核中的商品ID集合
  98. $goodIds = array_unique(array_diff($memberGoodsIds,$applyGoodsIds));
  99. // 获取列表记录
  100. $model = new GoodsModel;
  101. $params = $this->request->param();
  102. $params['sortType'] = 'create_time';
  103. $params['listType'] = 'on_sale';
  104. $params['goods_id_arr'] = $goodIds;
  105. $list = $model->getList($params);
  106. $memberGoods = MemberGoodsModel::whereIn('goods_id',$goodIds)->column('discount','goods_id');
  107. foreach ($list as &$item){
  108. $item['discount'] = $memberGoods[$item['goods_id']];
  109. }
  110. return $this->renderSuccess(compact('list'));
  111. }
  112. /**
  113. * 编辑
  114. * @return array
  115. * @author: zjwhust
  116. * @Time: 2022/5/25 16:56
  117. */
  118. // public function edit(int $id)
  119. // {
  120. // $postData = $this->postForm();
  121. // $model = ApplyModel::find($id);
  122. // $postData['audit_status'] = AuditStatus::AUDIT_WAIT;
  123. // $postData['audit_user'] = $this->store['user']['real_name']?:'';
  124. // $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:'';
  125. // if(!$model->edit($postData)){
  126. // return $this->renderError($model->getError() ?: '编辑失败');
  127. // }
  128. // return $this->renderSuccess([], '编辑成功');
  129. // }
  130. /**
  131. * 审核
  132. * @return array
  133. * @author: zjwhust
  134. * @Time: 2022/5/25 14:56
  135. */
  136. public function audit()
  137. {
  138. $postData = $this->postForm();
  139. $model = ApplyModel::find($postData['id']);
  140. $postData['audit_user'] = $this->store['user']['real_name']?:'';
  141. $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:'';
  142. if(!$model->audit($postData)){
  143. return $this->renderError($model->getError() ?: '审核失败');
  144. }
  145. return $this->renderSuccess([], '审核成功');
  146. }
  147. /**
  148. * 删除
  149. * @return array
  150. * @author: zjwhust
  151. * @Time: 2022/5/25 16:56
  152. */
  153. // public function delete()
  154. // {
  155. // $postData = $this->postForm();
  156. // $model = ApplyModel::find($postData['id']);
  157. // $postData['audit_user'] = $this->store['user']['real_name']?:'';
  158. // $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:'';
  159. // if(!$model->audit($postData)){
  160. // return $this->renderError($model->getError() ?: '审核失败');
  161. // }
  162. // return $this->renderSuccess([], '审核成功');
  163. // }
  164. }