123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace app\controller\store\mall;
-
- use app\controller\store\AuthController;
- use app\common\logic\DataLogic;
- use app\model\store\StoreUser;
- use app\model\user\User;
- use think\facade\Db;
-
- class FakeOrder extends AuthController{
- public function getMemberWithMobileFromFakeOrder()
- {
- $store_id=$this->storeId;
- $mobile = $this->request->param('mobile');
- if(empty($mobile) || !is_mobile($mobile)){
- return $this->fail('请输入正确的手机号');
- }
-
- if (!empty($mobile)) {
- //查询
- $user = new User();
- // $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') ?? [];
- $user_date = User::where([
- ['phone', '=', $mobile],
- ])->find() ?? [];
- return $this->success(['member'=>$user_date]);
- }else{
- return $this->fail('请输入正确的手机号');
- }
-
- }
-
- public function getGoodsFromFakeOrder()
- {
- $type=$this->request->param('type');
- if(empty($type)) return $this->fail('参数错误');
- if(!in_array($type,['normal','pre_sale','flash_sale','pin_tuan','store'])) return $this->fail('参数错误');
- switch ($type){
- case 'normal':
- $return=$this->getGoodsData();
- break;
- case 'pre_sale':
- $return=$this->getPreSaleGoodsData();
- break;
- case 'store':
- $return=$this->getStoreGoodsData();
- break;
- }
-
- return $this->success($return);
- }
-
- public function getGoodsByIdsFromFakeOrder()
- {
- $type=$this->request->param('type');
- $goods_ids=$this->request->param('goods_ids/a',[]);
- if(empty($type)) return $this->fail('参数错误');
- if(!in_array($type,['normal','pre_sale','store'])) return $this->fail('参数错误');
- if(empty($goods_ids) || !is_array($goods_ids)) return $this->fail('参数错误');
- switch ($type){
- case 'normal':
- $return=$this->getGoodsData($goods_ids);
- break;
- case 'pre_sale':
- $return=$this->getPreSaleGoodsData($goods_ids);
- break;
- case 'store':
- $return=$this->getStoreGoodsData($goods_ids);
- break;
- }
-
- return $this->success($return);
- }
-
- public function getFreightFromFakeOrder()
- {
- $province=$this->request->param('province');
- $num=$this->request->param('num/d',0);
- if(empty($province)) return $this->fail('请选择省份');
- if(empty($num) || $num<=0) return $this->fail('请选择商品');
- $freight_logic= new FreightLogic($this->request->shopId);
- $freight=$freight_logic->getFreightPrice($province,$num);
- if($freight == -1) return $this->fail('该地区暂不支持发货');
- return $this->success(['freight'=>$freight]);
-
- }
-
- public function createFakeOrder()
- {
- $type=$this->request->param('type');
- $member_id = $this->request->param('member_id/d',0);
- $logistics_type=$this->request->param('logistics_type/d');
- $receiving_name=$this->request->param('receiving_name');
- $receiving_mobile=$this->request->param('receiving_mobile');
- $receiving_address_province=$this->request->param('receiving_address_province');
- $receiving_address_city=$this->request->param('receiving_address_city');
- $receiving_address_county=$this->request->param('receiving_address_county');
- $receiving_address_info=$this->request->param('receiving_address_info');
- $total_price = $this->request->param('total_price/f',0);
- $need_pay=$this->request->param('need_pay/f',0);
- $goods=$this->request->param('goods/a',[]);
- $status=$this->request->param('status/d');
- $is_commission=$this->request->param('is_commission/d',0);
-
- if(empty($type)) return $this->fail('请选择商品');
- if(!in_array($type,['normal','pre_sale','store'])) return $this->fail('参数错误');
- if(empty($logistics_type)) return $this->fail('请选择配送方式');
- if(!in_array($logistics_type,[1,2])) return $this->fail('请选择配送方式');
- if(empty($status)) return $this->fail('请选择状态');
- if($type=='store'){
- if(!in_array($status,[4,8])) return $this->fail('请选择状态');
- }else{
- if($logistics_type==1 && !in_array($status,[2,8])) return $this->fail('请选择状态');
- }
- if(!in_array($is_commission,[0,1])) return $this->fail('请选择是否算合伙人业绩');
-
-
-
- $params=[
- 'member_id'=>$member_id,
- 'logistics_type'=>$logistics_type,
- 'receiving_name'=>$receiving_name,
- 'receiving_mobile'=>$receiving_mobile,
- 'receiving_address_province'=>$receiving_address_province,
- 'receiving_address_city'=>$receiving_address_city,
- 'receiving_address_county'=>$receiving_address_county,
- 'receiving_address_info'=>$receiving_address_info,
- 'total_price'=>$total_price,
- 'need_pay'=>$need_pay,
- 'goods'=>$goods,
- 'status'=>$status,
- ];
- Db::startTrans();
- try{
- $order_logic = OrderLogic::init($this->request->shopId);
- $order_id=$order_logic[$type]->createFakeOrder($params);
-
- if($is_commission==1){
- //记录推广员业绩
- $PartnerLogic = new PartnerLogic($this->request->shopId);
- $PartnerLogic->commission($member_id,$need_pay);
- }
-
- Db::commit();
- return $this->success(['order_id'=>$order_id]);
- } catch (\Exception $e){
- Db::rollback();
- return $this->fail($e->getMessage());
- }
- }
-
- protected function getGoodsData($goods_ids=[])
- {
- $name=$this->request->param('name');
- $where=[
- ['shop_id','=',$this->request->shopId],
- ['status','=',1],
- ['is_delete','=',0],
- ['is_open_yu','=',0],
- ];
- if(!empty($goods_ids)){
- $where[]=['goods_id','in',$goods_ids];
- }else{
- if(!empty($name)){
- $where[]=['name|code','like','%'.$name.'%'];
- }
- }
-
- $goods_model=new GoodsModel();
- $goods_model=$goods_model->with(['sku'=>function($query){
- $query->where([['is_delete','=',0],['shop_id','=',$this->request->shopId],['quota','>',0]]);
- }]);
- $order=['sort'=>'desc','fictitious_take_count'=>'desc','vip_price'=>'desc'];
- $field='goods_id,cover_img,name,original_price,vip_price,quota,take_count,fictitious_take_count';
- $append=['add_time_format'];
- $return=DataLogic::getDataList($goods_model,$where,$order,$field,$this->request->limit,$this->request->page,$append);
- return $return;
- }
-
- protected function getPreSaleGoodsData($goods_ids=[])
- {
- $name=$this->request->param('name');
- $where=[
- ['shop_id','=',$this->request->shopId],
- ['status','=',1],
- ['is_delete','=',0],
- ['is_open_yu','=',1],
- ];
- if(!empty($goods_ids)){
- $where[]=['goods_id','in',$goods_ids];
- }else{
- if(!empty($name)){
- $where[]=['name|code','like','%'.$name.'%'];
- }
- }
- $goods_model=new GoodsModel();
- $goods_model=$goods_model->with(['sku'=>function($query){
- $query->where([['is_delete','=',0],['shop_id','=',$this->request->shopId],['quota','>',0]]);
- }]);
- $order=['sort'=>'desc','fictitious_take_count'=>'desc','yu_price'=>'desc'];
- $field='goods_id,cover_img,name,original_price,quota,fictitious_take_count,is_open_yu,yu_days,yu_price';
- $append=['add_time_format'];
- $return=DataLogic::getDataList($goods_model,$where,$order,$field,$this->request->limit,$this->request->page,$append);
- return $return;
- }
-
-
- protected function getStoreGoodsData($store_goods_ids=[])
- {
- $name=$this->request->param('name');
- $where=[
- ['shop_id','=',$this->request->shopId],
- ['status','=',1],
- ['is_delete','=',0],
- ];
- //获取可用的商品id集合
- $goods_where=[
- ['shop_id','=',$this->request->shopId],
- ['status','=',1],
- ['is_delete','=',0],
- ['is_open_yu','=',0],
- ];
- if(!empty($name)) $goods_where[]=['name|code','like','%'.$name.'%'];
- $goods_ids=GoodsModel::where($goods_where)->column('goods_id') ?? [];
- $where[]=['goods_id','in',$goods_ids];
-
- if(!empty($store_goods_ids)) $where[]= ['store_goods_id','in',$store_goods_ids];
-
- $store_goods_model = new StoreGoodsModel();
- $store_goods_model = $store_goods_model->with(['goods'=>function($query){
- $query->field('goods_id,name,cover_img');
- }]);
- $order=['is_tui'=>'desc','fictitious_take_count'=>'desc','total_price'=>'asc'];
- $field='store_goods_id,num,goods_id,total_price,worth,fictitious_take_count,gift_giving';
- $append=['add_time_format'];
- $return=DataLogic::getDataList($store_goods_model,$where,$order,$field,$this->request->limit,$this->request->page,$append);
- return $return;
- }
- }
|