Index.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 商品管理
  7. */
  8. namespace app\ais\controller\shop;
  9. use app\ais\controller\Common;
  10. use app\ais\model\AisShop;
  11. use app\ais\model\AisShopCate;
  12. use app\ais\model\AisShopCoupon;
  13. use app\ais\model\AisCoupon;
  14. use app\ais\model\AisStore;
  15. use app\ais\model\Coupon;
  16. class Index extends Common{
  17. public function initialize() {
  18. parent::initialize();
  19. $this->assign('pathMaps',[['name'=>'优选宝贝','url'=>url("ais/shop/index")]]);
  20. }
  21. /**
  22. * 列表
  23. */
  24. public function index(){
  25. $condition = [];
  26. $status = $this->request->param('status');
  27. switch ($status) {
  28. case 'trash': //回收站
  29. $condition[] = ['is_del','=',1];
  30. break;
  31. case 'off_sale': //在售
  32. $condition[] = ['is_sale','=',1];
  33. $condition[] = ['is_del','=',0];
  34. break;
  35. case 'on_sale': //下架
  36. $condition[] = ['is_sale','=',0];
  37. $condition[] = ['is_del','=',0];
  38. break;
  39. default:
  40. $condition[] = ['is_del','=',0];
  41. break;
  42. }
  43. $keyword = $this->request->param('keyword');
  44. if(!empty($keyword)){
  45. $condition[] = ["name","like","%{$keyword}%"];
  46. }
  47. $cate_id = $this->request->param('cate_id/d',0);
  48. if($cate_id){
  49. $condition[] = ["category_id","=",$cate_id];
  50. }
  51. $view['lists'] = AisShop::where($this->mini_program)->where($condition)->order('id desc')->paginate(20,false,['query' => ['cate_id'=>$cate_id,'status' => $status,'keyword' => $keyword]]);
  52. $view['keyword'] = $keyword;
  53. $view['status'] = $status;
  54. $view['cate_id'] = $cate_id;
  55. $view['page'] = $this->request->param('page/d',0);
  56. return view()->assign($view);
  57. }
  58. /**
  59. * 编辑
  60. */
  61. public function edit(){
  62. if(request()->isAjax()){
  63. $param = [
  64. 'id' => $this->request->param('id/d',0),
  65. 'store_id' => $this->request->param('store_id/d'),
  66. 'category_id' => $this->request->param('category_id/d'),
  67. 'types' => $this->request->param('types/d', 0),
  68. 'name' => $this->request->param('name/s'),
  69. 'title' => $this->request->param('title/s'),
  70. 'sell_price' => $this->request->param('sell_price/f'),
  71. 'market_price' => $this->request->param('market_price/f', 0),
  72. 'cost_price' => $this->request->param('cost_price/f', 0),
  73. 'warehouse_num' => $this->request->param('warehouse_num/d', 0),
  74. 'warehouse_sellnum' => $this->request->param('warehouse_sellnum/d', 0),
  75. 'coupon_id' => $this->request->param('coupon_id/d', 0),
  76. 'vip_price' => $this->request->param('vip_price/f', 0),
  77. 'points_price' => $this->request->param('points_price/d', 0),
  78. 'share_vip_price' => $this->request->param('share_vip_price/d',0),
  79. 'share_price' => $this->request->param('share_price/d',0),
  80. 'imgs' => $this->request->param('imgs/a'),
  81. 'img' => $this->request->param('img/s'),
  82. 'content' => $this->request->param('content/s'),
  83. 'notice' => $this->request->param('notice/s'),
  84. 'keyword' => $this->request->param('keyword/s'),
  85. 'group_title' => $this->request->param('group_title/s'),
  86. 'group_note' => $this->request->param('group_note/s'),
  87. 'group_img' => $this->request->param('group_img/s'),
  88. 'end_time' => $this->request->param('end_time/s'),
  89. ];
  90. $validate = $this->validate($param,'shop.save');
  91. if(true !== $validate){
  92. return enjson(0,$validate);
  93. }
  94. $store = AisStore::where(['id' => $param['store_id']])->field('id,citycode')->find();
  95. $param['citycode'] = empty($store) ? 0:$store->citycode;
  96. $param['member_miniapp_id'] = $this->member_miniapp_id;
  97. $result = AisShop::edit($param);
  98. if($result){
  99. return enjson(200,['url' => url('ais/shop/index')]);
  100. }
  101. return enjson(0);
  102. }else{
  103. $view['id'] = $this->request->param('id/d');
  104. $view['info'] = AisShop::where(['id' => $view['id']])->find();
  105. $view['cate'] = AisShopCate::where($this->mini_program)->select();
  106. return view()->assign($view);
  107. }
  108. }
  109. /**
  110. * 删除
  111. */
  112. public function delete(){
  113. $id = $this->request->param('id/d',0);
  114. $ids = $this->request->param('ids/s');
  115. $result = AisShop::ids_delete($id,$ids);
  116. if($result){
  117. return enjson(200);
  118. }else{
  119. return enjson(403);
  120. }
  121. }
  122. /**
  123. * 上架,下架,从回收站恢复
  124. */
  125. public function ids_action(){
  126. if(request()->isAjax()){
  127. $issale = $this->request->param('issale/d');
  128. $ids = $this->request->param('ids/s');
  129. if(empty($ids)){
  130. return enjson(403,'没有选择任何要操作商品');
  131. }else{
  132. AisShop::ids_action($issale,$ids,$this->member_miniapp_id);
  133. return enjson(200);
  134. }
  135. }
  136. }
  137. /**
  138. * 商品栏目
  139. */
  140. public function category(){
  141. if(request()->isAjax()){
  142. $info = AisShopCate::where(['member_miniapp_id' => $this->member_miniapp_id,'parent_id' => $this->request->param('parent_id/d',0)])
  143. ->field('id,parent_id,title')
  144. ->order(['sort'=>'desc','id'=>'desc'])
  145. ->select();
  146. return enjson(200,'操作成功',$info);
  147. }else{
  148. $view['input'] = $this->request->param('input');
  149. $view['path'] = $this->request->param('path');
  150. return view('category',$view);
  151. }
  152. }
  153. /**
  154. *返回当前路径
  155. */
  156. public function category_path(){
  157. $info = AisShopCate::getPath($this->member_miniapp_id,$this->request->param('parent_id/d',0));
  158. if($info){
  159. $category = [];
  160. foreach ($info as $key => $value) {
  161. $category[] = $value['id'];
  162. }
  163. $category_id = implode(',',$category);
  164. return json(['code'=>200,'msg'=>'操作成功','data'=>$info,'category_id' => $category_id]);
  165. }
  166. return enjson(403,'读取商品分类路径失败');
  167. }
  168. /**
  169. * 计算价格
  170. */
  171. public function couponPrice(){
  172. $coupon_id = $this->request->param('coupon_id/d');
  173. $sell_price = $this->request->param('sell_price/f');
  174. $coupon = AisCoupon::where(['id' => $coupon_id])->find();
  175. if($coupon){
  176. if($coupon->types == 1){
  177. $coupon_user_price = $sell_price - $sell_price * $coupon->discount/10;
  178. }else{
  179. $coupon_user_price = $coupon->price;
  180. }
  181. }else{
  182. $coupon_user_price = 0;
  183. }
  184. return enjson(200,'成功',$coupon_user_price);
  185. }
  186. }