You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace app\controller\store\mall;
  3. use app\controller\store\AuthController;
  4. use app\common\logic\DataLogic;
  5. use app\model\store\StoreUser;
  6. use app\model\user\User;
  7. use think\facade\Db;
  8. class FakeOrder extends AuthController{
  9. public function getMemberWithMobileFromFakeOrder()
  10. {
  11. $store_id=$this->storeId;
  12. $mobile = $this->request->param('mobile');
  13. if(empty($mobile) || !is_mobile($mobile)){
  14. return $this->fail('请输入正确的手机号');
  15. }
  16. if (!empty($mobile)) {
  17. //查询
  18. $user = new User();
  19. // $member_ids = $store_user->alias('s')->join($user->getTable() . ' u', 's.uid = u.uid')->where('s.store_id', $store_id)->where('u.phone', $mobile)->column('s.uid') ?? [];
  20. $user_date = User::where([
  21. ['phone', '=', $mobile],
  22. ])->find() ?? [];
  23. return $this->success(['member'=>$user_date]);
  24. }else{
  25. return $this->fail('请输入正确的手机号');
  26. }
  27. }
  28. public function getGoodsFromFakeOrder()
  29. {
  30. $type=$this->request->param('type');
  31. if(empty($type)) return $this->fail('参数错误');
  32. if(!in_array($type,['normal','pre_sale','flash_sale','pin_tuan','store'])) return $this->fail('参数错误');
  33. switch ($type){
  34. case 'normal':
  35. $return=$this->getGoodsData();
  36. break;
  37. case 'pre_sale':
  38. $return=$this->getPreSaleGoodsData();
  39. break;
  40. case 'store':
  41. $return=$this->getStoreGoodsData();
  42. break;
  43. }
  44. return $this->success($return);
  45. }
  46. public function getGoodsByIdsFromFakeOrder()
  47. {
  48. $type=$this->request->param('type');
  49. $goods_ids=$this->request->param('goods_ids/a',[]);
  50. if(empty($type)) return $this->fail('参数错误');
  51. if(!in_array($type,['normal','pre_sale','store'])) return $this->fail('参数错误');
  52. if(empty($goods_ids) || !is_array($goods_ids)) return $this->fail('参数错误');
  53. switch ($type){
  54. case 'normal':
  55. $return=$this->getGoodsData($goods_ids);
  56. break;
  57. case 'pre_sale':
  58. $return=$this->getPreSaleGoodsData($goods_ids);
  59. break;
  60. case 'store':
  61. $return=$this->getStoreGoodsData($goods_ids);
  62. break;
  63. }
  64. return $this->success($return);
  65. }
  66. public function getFreightFromFakeOrder()
  67. {
  68. $province=$this->request->param('province');
  69. $num=$this->request->param('num/d',0);
  70. if(empty($province)) return $this->fail('请选择省份');
  71. if(empty($num) || $num<=0) return $this->fail('请选择商品');
  72. $freight_logic= new FreightLogic($this->request->shopId);
  73. $freight=$freight_logic->getFreightPrice($province,$num);
  74. if($freight == -1) return $this->fail('该地区暂不支持发货');
  75. return $this->success(['freight'=>$freight]);
  76. }
  77. public function createFakeOrder()
  78. {
  79. $type=$this->request->param('type');
  80. $member_id = $this->request->param('member_id/d',0);
  81. $logistics_type=$this->request->param('logistics_type/d');
  82. $receiving_name=$this->request->param('receiving_name');
  83. $receiving_mobile=$this->request->param('receiving_mobile');
  84. $receiving_address_province=$this->request->param('receiving_address_province');
  85. $receiving_address_city=$this->request->param('receiving_address_city');
  86. $receiving_address_county=$this->request->param('receiving_address_county');
  87. $receiving_address_info=$this->request->param('receiving_address_info');
  88. $total_price = $this->request->param('total_price/f',0);
  89. $need_pay=$this->request->param('need_pay/f',0);
  90. $goods=$this->request->param('goods/a',[]);
  91. $status=$this->request->param('status/d');
  92. $is_commission=$this->request->param('is_commission/d',0);
  93. if(empty($type)) return $this->fail('请选择商品');
  94. if(!in_array($type,['normal','pre_sale','store'])) return $this->fail('参数错误');
  95. if(empty($logistics_type)) return $this->fail('请选择配送方式');
  96. if(!in_array($logistics_type,[1,2])) return $this->fail('请选择配送方式');
  97. if(empty($status)) return $this->fail('请选择状态');
  98. if($type=='store'){
  99. if(!in_array($status,[4,8])) return $this->fail('请选择状态');
  100. }else{
  101. if($logistics_type==1 && !in_array($status,[2,8])) return $this->fail('请选择状态');
  102. }
  103. if(!in_array($is_commission,[0,1])) return $this->fail('请选择是否算合伙人业绩');
  104. $params=[
  105. 'member_id'=>$member_id,
  106. 'logistics_type'=>$logistics_type,
  107. 'receiving_name'=>$receiving_name,
  108. 'receiving_mobile'=>$receiving_mobile,
  109. 'receiving_address_province'=>$receiving_address_province,
  110. 'receiving_address_city'=>$receiving_address_city,
  111. 'receiving_address_county'=>$receiving_address_county,
  112. 'receiving_address_info'=>$receiving_address_info,
  113. 'total_price'=>$total_price,
  114. 'need_pay'=>$need_pay,
  115. 'goods'=>$goods,
  116. 'status'=>$status,
  117. ];
  118. Db::startTrans();
  119. try{
  120. $order_logic = OrderLogic::init($this->request->shopId);
  121. $order_id=$order_logic[$type]->createFakeOrder($params);
  122. if($is_commission==1){
  123. //记录推广员业绩
  124. $PartnerLogic = new PartnerLogic($this->request->shopId);
  125. $PartnerLogic->commission($member_id,$need_pay);
  126. }
  127. Db::commit();
  128. return $this->success(['order_id'=>$order_id]);
  129. } catch (\Exception $e){
  130. Db::rollback();
  131. return $this->fail($e->getMessage());
  132. }
  133. }
  134. protected function getGoodsData($goods_ids=[])
  135. {
  136. $name=$this->request->param('name');
  137. $where=[
  138. ['shop_id','=',$this->request->shopId],
  139. ['status','=',1],
  140. ['is_delete','=',0],
  141. ['is_open_yu','=',0],
  142. ];
  143. if(!empty($goods_ids)){
  144. $where[]=['goods_id','in',$goods_ids];
  145. }else{
  146. if(!empty($name)){
  147. $where[]=['name|code','like','%'.$name.'%'];
  148. }
  149. }
  150. $goods_model=new GoodsModel();
  151. $goods_model=$goods_model->with(['sku'=>function($query){
  152. $query->where([['is_delete','=',0],['shop_id','=',$this->request->shopId],['quota','>',0]]);
  153. }]);
  154. $order=['sort'=>'desc','fictitious_take_count'=>'desc','vip_price'=>'desc'];
  155. $field='goods_id,cover_img,name,original_price,vip_price,quota,take_count,fictitious_take_count';
  156. $append=['add_time_format'];
  157. $return=DataLogic::getDataList($goods_model,$where,$order,$field,$this->request->limit,$this->request->page,$append);
  158. return $return;
  159. }
  160. protected function getPreSaleGoodsData($goods_ids=[])
  161. {
  162. $name=$this->request->param('name');
  163. $where=[
  164. ['shop_id','=',$this->request->shopId],
  165. ['status','=',1],
  166. ['is_delete','=',0],
  167. ['is_open_yu','=',1],
  168. ];
  169. if(!empty($goods_ids)){
  170. $where[]=['goods_id','in',$goods_ids];
  171. }else{
  172. if(!empty($name)){
  173. $where[]=['name|code','like','%'.$name.'%'];
  174. }
  175. }
  176. $goods_model=new GoodsModel();
  177. $goods_model=$goods_model->with(['sku'=>function($query){
  178. $query->where([['is_delete','=',0],['shop_id','=',$this->request->shopId],['quota','>',0]]);
  179. }]);
  180. $order=['sort'=>'desc','fictitious_take_count'=>'desc','yu_price'=>'desc'];
  181. $field='goods_id,cover_img,name,original_price,quota,fictitious_take_count,is_open_yu,yu_days,yu_price';
  182. $append=['add_time_format'];
  183. $return=DataLogic::getDataList($goods_model,$where,$order,$field,$this->request->limit,$this->request->page,$append);
  184. return $return;
  185. }
  186. protected function getStoreGoodsData($store_goods_ids=[])
  187. {
  188. $name=$this->request->param('name');
  189. $where=[
  190. ['shop_id','=',$this->request->shopId],
  191. ['status','=',1],
  192. ['is_delete','=',0],
  193. ];
  194. //获取可用的商品id集合
  195. $goods_where=[
  196. ['shop_id','=',$this->request->shopId],
  197. ['status','=',1],
  198. ['is_delete','=',0],
  199. ['is_open_yu','=',0],
  200. ];
  201. if(!empty($name)) $goods_where[]=['name|code','like','%'.$name.'%'];
  202. $goods_ids=GoodsModel::where($goods_where)->column('goods_id') ?? [];
  203. $where[]=['goods_id','in',$goods_ids];
  204. if(!empty($store_goods_ids)) $where[]= ['store_goods_id','in',$store_goods_ids];
  205. $store_goods_model = new StoreGoodsModel();
  206. $store_goods_model = $store_goods_model->with(['goods'=>function($query){
  207. $query->field('goods_id,name,cover_img');
  208. }]);
  209. $order=['is_tui'=>'desc','fictitious_take_count'=>'desc','total_price'=>'asc'];
  210. $field='store_goods_id,num,goods_id,total_price,worth,fictitious_take_count,gift_giving';
  211. $append=['add_time_format'];
  212. $return=DataLogic::getDataList($store_goods_model,$where,$order,$field,$this->request->limit,$this->request->page,$append);
  213. return $return;
  214. }
  215. }