123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981 |
- <?php
- namespace app\api\controller;
- use app\admin\model\Attribute;
- use app\admin\model\Label;
- use app\api\model\Category;
- use app\api\model\ShopUserOld;
- use app\api\model\StoreEvaluate;
- use app\api\model\StoreOrder;
- use app\api\model\StoreProduct;
- use app\admin\model\store\StoreProductAttribute;
- use app\api\model\StoreSeckill;
- use app\common\controller\Api;
- use app\api\model\ShopUser;
- class Shop extends Api
- {
- protected $noNeedLogin =[ 'attribute','attribute_xh','label','category','store_list'];
-
- public function category(){
- $where = ['status' => 'normal'];
- $where['pid']=0;
- $list = Category::where($where)
-
- ->with('catelist')
- ->field('id,name,pid')
- ->order('weigh desc,id desc')
- ->select();
- $this->result('ok', $list, 1);
- }
-
- public function apply_shop(){
- $userId = $this->request->param('user_id');
- $shop_user_id=$this->request->param('shop_user_id');
- $get_is=ShopUser::where(['mid'=>$userId])->find();
- if(!empty($get_is)){
- if ($get_is['status']==0){
- $this->result('您提交的资料正在审核,请耐心等待',$get_is,'101');
- }elseif ($get_is['status']=='1' || $get_is['status']=='4'|| $get_is['status']=='5'){
- $this->result('您已经成为商家',$get_is,'103');
- }else{
- if (empty($shop_user_id)){
- $this->result('您提交的资料审核失败,请重新修改',$get_is,'102');
- }
- }
- }
- $post_array=$this->request->post();
- $name=$post_array['name'];
- $shopname=$post_array['shopname'];
- $phone=$post_array['phone'];
- $effect_city=$post_array['effect_city'];
- $city=$post_array['city'];
- $address=$post_array['address'];
- $cate_id=$post_array['cate_id'];
- $cate_top_id=$post_array['cate_top_id'];
- $type_id=$post_array['type_id'];
- $image=str_replace(config('site.siteUrl'),'',$post_array['image']);
- $images=str_replace(config('site.siteUrl'),'',$post_array['images']);
- if (empty($name) || empty($phone) || empty($effect_city) || empty($city)|| empty($address) || empty($cate_id) ){
- $this->result('数据丢失');
- }
- $time=time();
- $date=[
- 'mid'=>$userId,
- 'shopname'=>$shopname,
- 'name'=>$name,
- 'phone'=>$phone,
- 'cate_id'=>$cate_id,
- 'cate_top_id'=>$cate_top_id,
- 'type_id'=>$type_id,
- 'effect_city'=>$effect_city,
- 'city'=>$city,
- 'address'=>$address,
- 'status'=>0,
- 'image'=>$image,
- 'images'=>$images,
- 'updatetime'=>$time
- ];
- if (!empty($shop_user_id)){
- ShopUser::where('id',$shop_user_id)->update($date);
- $this->result('申请已经重新提交,等待审核', $shop_user_id, 1);
- }else{
- $date['createtime']=$time;
- if(ShopUser::insert($date)){
- $bid = ShopUser::getLastInsID();
- $this->result('申请已经提交,等待审核', $bid, 1);
- }else{
- $this->result('申请失败,请重新提交');
- }
- }
- }
-
- public function shop_info(){
- $userId = $this->request->post('user_id');
- $type = $this->request->post('type');
- $shop_user_id=$this->request->post('shop_user_id');
- if (empty($userId)){
- $this->result('系统错误,刷新重试');
- }
- if (!$type) {
- $type=1;
- }
- $get_is=ShopUser::where(['mid'=>$userId])->find();
- if(!empty($get_is)){
- if ($get_is['status']==0){
- $this->result('您提交的资料正在审核,请耐心等待',$get_is,'101');
- }elseif ($get_is['status']=='1' || $get_is['status']=='4' || $get_is['status']=='5'){
- if ($type==1){
- $this->result('SUCCESS', $get_is, 1);
- }else{
- $post_array=$this->request->post();
- $name=$post_array['name'];
- $phone=$post_array['phone'];
- $city=$post_array['city'];
-
- $address=$post_array['address'];
- $image=str_replace(config('site.siteUrl'),'',$post_array['image']);
- $images=str_replace(config('site.siteUrl'),'',$post_array['images']);
- $time=time();
- $date=[
- 'name'=>$name,
- 'phone'=>$phone,
- 'city'=>$city,
- 'address'=>$address,
- 'status'=>4,
- 'image'=>$image,
- 'images'=>$images,
- 'updatetime'=>$time
- ];
- if (!empty($post_array['effect_city'])){
- $date['effect_city']=$post_array['effect_city'];
- }
- ShopUser::where(['mid'=>$userId])->update($date);
- $image=str_replace(config('site.siteUrl').'/',"/",$get_is['image']);
- $images=str_replace(config('site.siteUrl').'/',"/",$get_is['images']);
- $image=str_replace(config('site.siteUrl'),"/",$image);
- $images=str_replace(config('site.siteUrl'),"/",$images);
- $insert=[
- 'suser_id'=>$get_is['id'],
- 'shopname'=>$get_is['shopname'],
- 'name'=>$get_is['name'],
- 'phone'=>$get_is['phone'],
- 'city'=>$get_is['city'],
- 'description'=>$get_is['description'],
- 'effect_city'=> $get_is['effect_city'],
- 'address'=>$get_is['address'],
- 'status'=>$get_is['status'],
- 'image'=>$image,
- 'images'=>implode(',',$images),
- 'updatetime'=>$time,
- 'createtime'=>$time
- ];
- ShopUserOld::insert($insert);
-
- $this->result('申请已经重新提交,等待审核', $shop_user_id, 1);
- }
- }else{
- $this->result('您提交的资料审核失败,请重新修改',$get_is,'102');
- }
- }else{
- $this->result('您不是商家,请先去申请入驻');
- }
- }
-
- public function store_list(){
- $userId = $this->request->post('user_id');
- $suser_id= $this->request->post('suser_id');
- $search = $this->request->post('search');
- $cate_id = $this->request->post('cate_id');
- $where['is_del']=array('eq',0);
- if (!empty($suser_id)){
- $where['suser_id']=$suser_id;
- }
- if (!empty($search)){
- $where['store_name']=array('like','%'.$search.'%');
- }
- if (!empty($cate_id)){
- $where['cate_id']=$cate_id;
- }
- $list=StoreProduct::where($where)->field('id,slider_image,image,store_name,deposit_price,price,false as shop_show,cate_top_id ')->order('id desc')->select();
- foreach ($list as $k=>$v){
- $v['shop_show']=false;
- }
- $this->result('success', $list, 1);
- }
-
- public function attribute(){
- $cate_top_id = $this->request->post('cate_top_id');
- if (empty($cate_top_id)){
- $cate_top_id='0';
- }
- if ($cate_top_id=='17'){
- $whereArr['cate_top_id'] = array('in',['0','17']);
- }
- if ($cate_top_id=='18'){
- $whereArr['cate_top_id'] = array('in',['0','18']);
- }
- $whereArr['pid'] = array('eq',0);
- $whereArr['id'] = array('neq','4');
- $list = Attribute::where('status',1)
- ->where($whereArr)
- ->with('attlist')
- ->order('weigh desc,id desc')
- ->select();
- $this->result('SUCCESS', $list, 1);
- }
-
- public function label(){
- $cate_top_id = $this->request->post('cate_top_id');
- if (empty($cate_top_id)){
- $cate_top_id='0';
- }
- if ($cate_top_id=='17'){
- $whereArr['cate_top_id'] = array('in',['0','17']);
- }
- if ($cate_top_id=='18'){
- $whereArr['cate_top_id'] = array('in',['0','18']);
- }
- if ($cate_top_id=='15'){
- $whereArr['cate_top_id'] = array('in',['0','15']);
- }
- $list = Label::where('status',1)
- ->field('id,name')
- ->order('weigh desc,id desc')
- ->select();
- $this->result('SUCCESS', $list, 1);
- }
-
- public function attribute_xh(){
- $pid = $this->request->post('pid');
- $whereArr['pid'] = array('eq',$pid);
- $list = Attribute::where('status',1)
- ->where($whereArr)
- ->order('weigh desc,id desc')
- ->select();
- $this->result('SUCCESS', $list, 1);
- }
-
- public function store_add(){
- $userId = $this->request->post('user_id');
- $type = $this->request->post('type');
- $store_id = $this->request->post('store_id');
- if ($type==2 && empty($store_id)){
- $this->result('系统错误,刷新重试');
- }
- $get_is=ShopUser::where(['mid'=>$userId])->find();
- if(!empty($get_is)){
- if($get_is['status']!='1'){
- $this->result('您提交的信息正在审核,现在无法发布商品');
- }else{
- if (empty($type)){
- $type=1;
- }
- $time=time();
- $post=$this->request->post('',null,null);
- $insert['car_number']=mt_rand('1000000','9999999');
- $insert['suser_id']=$post['suser_id'];
- $insert['store_name']=$post['store_name'];
- $insert['store_info']=$post['store_info'];
- $image=str_replace(config('site.siteUrl'),"/",$post['image']);
- $slider_image=str_replace(config('site.siteUrl'),"/",$post['slider_image']);
- $mp4=str_replace(config('site.siteUrl'),"/",$post['mp4']);
- $insert['image']=str_replace('//u',"/u",$image);
- $insert['slider_image']=str_replace('//u',"/u",$slider_image);
- $insert['mp4']=str_replace('//u'.'/',"/u",$mp4);
- $insert['cate_id']=$post['cate_id'];
- $insert['cate_top_id']=$post['cate_top_id'];
- $insert['one_commission']=empty($post['one_commission'])?'0':$post['one_commission'];;
- $insert['two_commission']=empty($post['two_commission'])?'0':$post['two_commission'];;
- if (($insert['one_commission']+ $insert['two_commission'])>=100){
- $this->result('佣金比例最高100');
- }
- $insert['price']=$post['price'];
- $insert['deposit_price']=$post['deposit_price'];
- $insert['special_price']=$post['special_price'];
- $insert['stock']=$post['stock'];
- $insert['is_show']=$post['is_show'];
- $insert['is_seckill']=empty($post['is_seckill'])?'0':$post['is_seckill'];
- $insert['description']=$post['description'];
- $insert['feight_id']=$post['feight_id'];
- $insert['updatetime']=$time;
- $label=$this->request->post('label');
- if (!empty($label)){
- $insert['label']=$label;
- }
- $car_start_date=$this->request->post('car_start_date');
- if (!empty($car_start_date)){
- $insert['car_start_date']=$car_start_date;
- }
- $car_distance=$this->request->post('car_distance');
- if (!empty($car_distance)){
- $insert['car_distance']=$car_distance;
- }
- if ($type==1){
- $insert['createtime']=$time;
- if(StoreProduct::insert($insert)){
- $bid = StoreProduct::getLastInsID();
- $insert_seckill['store_id']=$bid;
- $insert_seckill['sort']='1';
- $insert_seckill['is_hot']='0';
- $insert_seckill['sales']='0';
- $insert_seckill['add_time']=time();
- $insert_seckill['price']=empty($post['seckill_price'])?date('Y-m-d'):$post['seckill_price'];
- $insert_seckill['stock']=empty($post['seckill_stock'])?'0':$post['seckill_stock'];
- $insert_seckill['start_time']=empty($post['seckill_start_time'])?date('Y-m-d'):$post['seckill_start_time'];
- $insert_seckill['time_id']=empty($post['seckill_time_id'])?'0':$post['seckill_time_id'];
- if (empty($post['is_seckill'])){
- $insert_seckill['is_show']='0';
- }else{
- $insert_seckill['is_show']='1';
- }
- StoreSeckill::insert($insert_seckill);
- if ($post['cate_top_id']=='14'){
- if (!empty($post['attribute'])){
- $attribute=$post['attribute'];
- $attribute_array=explode(',',$attribute);
- $insert_attr['suser_id']=$post['suser_id'];
- $insert_attr['pro_id']=$bid;
- foreach ($attribute_array as $k=>$v){
- $a=explode(':',$v);
- if (!empty($a)){
- $insert_attr['attribute_id']=$a['0'];
- if (empty($a['1'])){
- $insert_attr['attribute_list_id']=0;
- $insert_attr['attribute_list_value']=$a['2'];
- }else{
- $insert_attr['attribute_list_id']=$a['1'];
- $insert_attr['attribute_list_value']=$a['2'];
- }
- $insert_attr['createtime']=$insert_attr['updatetime']=time();
- StoreProductAttribute::insert($insert_attr);
- if ($a['0']==4 && empty($insert['store_name'])){
- $get_a = Attribute::where('id',$a['1'])->field('name')->find();
- if (!empty($a['2'])){
- $get_b = Attribute::where('id',$a['2'])->field('name')->find();
- $store_name=$get_a['name'].' '.$get_b['name'];
- }else{
- $store_name=$get_a['name'];
- }
- $save = StoreProduct::where('id', $bid)
- ->update(['store_name'=>$store_name]);
- }
- }
- }
- }
- }
- $this->result('SUCCESS', $bid, 1);
- }else{
- $this->result('发布失败,稍后重试');
- }
- }else{
- $save = StoreProduct::where('id', $store_id)
- ->update($insert);
- $insert_seckill['price']=empty($post['seckill_price'])?date('Y-m-d'):$post['seckill_price'];
- $insert_seckill['stock']=empty($post['seckill_stock'])?'0':$post['seckill_stock'];
- $insert_seckill['start_time']=empty($post['seckill_start_time'])?date('Y-m-d'):$post['seckill_start_time'];
- $insert_seckill['time_id']=empty($post['seckill_time_id'])?'0':$post['seckill_time_id'];
- if (empty($post['is_seckill'])){
- $insert_seckill['is_show']='0';
- }else{
- $insert_seckill['is_show']='1';
- }
- $get_seck= StoreSeckill::where('store_id', $store_id)->find();
- if (empty($get_seck)){
- $insert_seckill['store_id']=$store_id;
- $insert_seckill['sort']='1';
- $insert_seckill['is_hot']='0';
- $insert_seckill['sales']='0';
- $insert_seckill['add_time']=time();
- StoreSeckill::insert($insert_seckill);
- }else{
- StoreSeckill::where('store_id', $store_id)->update($insert_seckill);
- }
- if ($post['cate_top_id']=='14') {
- $attribute=$post['attribute'];
- $attribute_array=explode(',',$attribute);
- $insert_attr['suser_id']=$post['suser_id'];
- $insert_attr['pro_id']=$store_id;
- StoreProductAttribute::where('pro_id',$store_id)->delete();
- if (!empty($attribute_array)){
- foreach ($attribute_array as $k=>$v){
- $a=explode(':',$v);
- if (!empty($a)){
- $insert_attr['attribute_id']=$a['0'];
- if (empty($a['1'])){
- $insert_attr['attribute_list_id']=0;
- $insert_attr['attribute_list_value']=$a['2'];
- }else{
- $insert_attr['attribute_list_id']=$a['1'];
- $insert_attr['attribute_list_value']=$a['2'];
- }
- $insert_attr['createtime']=$insert_attr['updatetime']=time();
- StoreProductAttribute::insert($insert_attr);
- if ($a['0']==4 && empty($insert['store_name'])){
- $get_a = Attribute::where('id',$a['1'])->field('name')->find();
- if (!empty($a['2'])){
- $get_b = Attribute::where('id',$a['2'])->field('name')->find();
- $store_name=$get_a['name'].' '.$get_b['name'];
- }else{
- $store_name=$get_a['name'];
- }
- $save = StoreProduct::where('id', $store_id)
- ->update(['store_name'=>$store_name]);
- }
- }
- }
- }
- }
- $this->result('SUCCESS'.$post['is_seckill'], $store_id, 1);
- }
- }
- }else{
- $this->result('您不是商家,无法发布商品');
- }
- }
-
- public function store_info(){
- $store_id = $this->request->post('store_id');
- $suser_id = $this->request->post('suser_id');
- if (empty($store_id)){
- $this->result('系统错误,刷新重试');
- }
- $where['id']=$store_id;
- $where['suser_id']=$suser_id;
- $where['is_del']=array('eq',0);
- $get=StoreProduct::where($where)->with(['storeseckill','storeseckill.seckilltime','attribute'])->find();
- if (empty($get)){
- $this->result('商品不存在');
- }
- $list = Attribute::where('status',1)
- ->where(['pid'=>0])
- ->with('attlist')
- ->order('weigh desc,id desc')
- ->select();
- if (!empty($list)){
- $pro_list['id']='';
- $pro_list['attribute_list_id']='';
- $pro_list['attribute_list_value']='';
- foreach ($list as $k=>$v){
- $pro=StoreProductAttribute::where('pro_id',$store_id)->with('attribute')->where('attribute_id',$v['id'])->find();
- if (!empty($pro)){
- $list[$k]['pro']=$pro;
- }else{
- $list[$k]['pro']=$pro_list;
- }
- }
- }
- $get['attribute_list']=$list;
- $label_array=[];
- if (!empty($get['label'])){
- foreach ($get['label'] as $k=>$v){
- $list = Label::where('id',$v)
- ->field('id,name')
- ->find();
- $label_array[]=$list;
- }
- }
- if (!empty($get['attribute'])){
- foreach ($get['attribute'] as $k=>$v){
- if ($v['attribute_id']=='4'){
- if (!empty($v['attribute_list_value'])){
- $a = Attribute::where(['id'=>$v['attribute_list_value']])
- ->find();
- $get['xinghao']=$a;
- }
- }
- }
- }
- $get['label']=$label_array;
- $this->result('SUCCESS',$get,1);
- }
-
- public function store_del(){
- $store_id = $this->request->post('store_id');
- $suser_id = $this->request->post('suser_id');
- if (empty($store_id)){
- $this->result('系统错误,刷新重试');
- }
- $where['id']=$store_id;
- $where['suser_id']=$suser_id;
- $where['is_del']=array('eq',0);
- $get=StoreProduct::where($where)->field('id')->find();
- if (empty($get)){
- $this->result('商品不存在');
- }
- $insert['is_del']=1;
- $insert['updatetime']=time();
- $save = StoreProduct::where('id', $store_id)
- ->update($insert);
- StoreSeckill::where('store_id', $store_id)
- ->update(['is_del'=>'1']);
- $this->result('SUCCESS', $store_id, 1);
- }
-
- public function order_list(){
- $suser_id = $this->request->post('suser_id');
- $search = $this->request->post('search');
- if (empty($suser_id)){
- $this->result('系统错误,刷新重试');
- }
- $type = $this->request->post('type');
- if (empty($type)){
- $type=0;
- }
- if (!empty($search)){
- $where['store_name']=array('like','%'.$search.'%');
- }
- if ($type==14){
- $where['cate_id']=14;
- $where['status']=['in',['3','4']];
- }else{
- $where['cate_id']=15;
- if ($type=='1'){
- $where['status']=['eq','1'];
- }elseif($type=='2'){
- $where['status']=['eq','2'];
- }elseif($type=='3'){
- $where['status']=['in',['3','4']];
- }elseif($type=='-1'){
- $where['status']=['in',['-1','-2','-3','-4','-5']];
- }
- }
- $where['suser_id']=$suser_id;
- $where['is_del']=0;
- $where['is_system_del']=0;
- $get_order=StoreOrder::where($where)
- ->where('status','neq','9')
- ->with(['member','product'])
- ->field('id,order_id,total_price,total_num,freight_price,mid,suser_id,store_product_id,prepay_id,status,mark,delivery_id,delivery_name,commission_price')
- ->order('id','desc')
- ->select();
- $this->result('SUCCESS', $get_order, 1);
- }
-
- public function order_info(){
- $user_id = $this->request->post('user_id');
- $id = $this->request->post('order_id');
- $suser_id = $this->request->post('suser_id');
- $where['id']=$id;
- $where['suser_id']=$suser_id;
- $where['is_del']=0;
- $where['is_system_del']=0;
- $get_order=StoreOrder::where($where)
- ->with(['product','express','refundexpress'])
-
- ->find();
- if (empty($get_order)){
- $this->result('此订单已删除');
- }
- $this->result('success',$get_order,1);
- }
-
- public function order_deliver(){
- $user_id = $this->request->post('user_id');
- $id = $this->request->post('order_id');
- $suser_id = $this->request->post('suser_id');
- $delivery_name = $this->request->post('delivery_name');
- $delivery_id = $this->request->post('delivery_id');
-
- $where['suser_id']=$suser_id;
- $where['id']=$id;
- $where['is_del']=0;
- $where['is_system_del']=0;
- $where['status']=['in',['1','2','-3']];
-
- $get_order=StoreOrder::where($where)
- ->field('id,status,delivery_id')
- ->find();
-
- if (empty($get_order)){
- $this->result('此订单不能操作发货');
- }
- if (!empty($delivery_name) && !empty($delivery_id)){
- StoreOrder::where(['id' => $id])->update(['delivery_name'=>$delivery_name,'delivery_id'=>$delivery_id,'status'=>'2']);
- }
- $this->result('success',$get_order,1);
- }
-
- public function order_refund(){
- $user_id = $this->request->post('user_id');
- $id = $this->request->post('order_id');
- $suser_id = $this->request->post('suser_id');
- $refund_reason= $this->request->post('refund_reason');
- $refund_status = $this->request->post('refund_status');
-
- $where['suser_id']=$suser_id;
- $where['id']=$id;
- $where['id']=$id;
- $where['is_del']=0;
- $where['is_system_del']=0;
- $where['status']=['in',['-1','-2','-3','-4']];
- $get_order=StoreOrder::where($where)
- ->field('id,status,refund_status,refund_type,order_id,pay_price,refund_price')
- ->find();
- if (empty($get_order)){
- $this->result('此订单不能再次进行退款操作');
- }
- if ($refund_status==1 || $refund_status==3){
- if ($get_order['refund_status'] !='4'){
- StoreOrder::where(['id' => $id])->update(['refund_status'=>$refund_status,'refund_reason'=>$refund_reason,'status'=>0-$refund_status]);
- $this->result('success',$get_order,1);
- }
- }elseif($refund_status==2){
- if ($get_order['refund_type']=='0'){
- if ($get_order['refund_status'] !='4'){
- StoreOrder::where(['id' => $id])->update(['refund_status'=>$refund_status,'refund_reason'=>$refund_reason,'status'=>0-$refund_status]);
- $this->result('success',$get_order,1);
- }
- }else{
- if ($get_order['refund_status'] !='5'){
- $reoderSn=$get_order['order_id'];
-
- $money =$get_order['pay_price'];
- $wx = new WxPay();
- $body = '订单号' . $get_order['order_id'];
- $out_trade_no = $reoderSn;
- $total_fee = $money * 100;
- $refund_fee=$get_order['refund_price']*100;
- $order = $wx->wxrefund($out_trade_no,date('YmdHis').time(),$total_fee,$refund_fee);
-
- if(($order['return_code']=='SUCCESS') && ($order['result_code']=='SUCCESS')){
- StoreOrder::where(['id' => $id])->update(['refund_status'=>'5','refund_reason'=>$refund_reason,'status'=>'-5']);
- $this->result('success',$get_order,1);
- }else if(($order['return_code']=='FAIL') || $order['result_code']=='FAIL' ){
- $reason = (empty($order['err_code_des'])?$order['return_msg']:$order['err_code_des']);
- $this->result('退款失败',$reason);
- }else{
- $this->result('退款失败');
- }
- }
- }
- }elseif($refund_status=5){
- if ($get_order['refund_status'] !='5'){
- $reoderSn=$get_order['order_id'];
-
- $money =$get_order['pay_price'];
- $wx = new WxPay();
- $body = '订单号' . $get_order['order_id'];
- $out_trade_no = $reoderSn;
- $total_fee = $money * 100;
- $refund_fee=$get_order['refund_price']*100;
- $order = $wx->wxrefund($out_trade_no,date('YmdHis').time(),$total_fee,$refund_fee);
-
- if(($order['return_code']=='SUCCESS') && ($order['result_code']=='SUCCESS')){
- StoreOrder::where(['id' => $id])->update(['refund_status'=>$refund_status,'refund_reason'=>$refund_reason,'status'=>0-$refund_status]);
- $this->result('success',$get_order,1);
- }else if(($order['return_code']=='FAIL') || $order['result_code']=='FAIL' ){
- $reason = (empty($order['err_code_des'])?$order['return_msg']:$order['err_code_des']);
- $this->result('退款失败',$reason);
- }else{
- $this->result('退款失败');
- }
- }
- $this->result('退款失败');
- }
- }
-
- public function order_evaluate(){
- $user_id = $this->request->post('user_id');
- $id = $this->request->post('order_id');
- $suser_id = $this->request->post('suser_id');
- $get= StoreEvaluate::where('order_id',$id)->with(['member','reply','shopuser'])->where('pid','0')->find();
- if (!empty($get)){
- $get['add_time']=$get['createtime'];
- }
- $this->result('success',$get,1);
- }
-
- public function order_evaluate_huifu(){
- $user_id = $this->request->post('user_id');
- $id = $this->request->post('order_id');
- $evaluate_id = $this->request->post('evaluate_id');
- $content= $this->request->post('content');
- $get= StoreEvaluate::where('order_id',$id)->where('pid','0')->where('id',$evaluate_id)->find();
- StoreEvaluate::where('order_id',$id)->where('pid',$get['id'])->delete();
- $insert['mid']='';
- $insert['store_id']=$get['store_id'];
- $insert['order_id']=$get['order_id'];
- $insert['suser_id']=$get['suser_id'];
- $insert['xj']='0';
- $insert['content']=$content;
- $insert['pid']=$get['id'];
- $insert['status']=1;
- $insert['createtime']=$insert['updatetime']=time();
- StoreEvaluate::insert($insert);
- $this->result('success',$get,1);
- }
-
- function getthemonth($date)
- {
- $firstday = date('Y-m-01', strtotime($date));
- $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
- return array($firstday, $lastday);
- }
- public function take_order_list(){
- $suser_id = $this->request->post('suser_id');
- if (empty($suser_id)){
- $this->result('系统错误,刷新重试');
- }
- $mouth = $this->request->post('mouth');
- $type= $this->request->post('type');
- if (empty($mouth) || $mouth=='本月'){
- $mouth=date('Y-m');
- }
- if ($type=='年'){
- $start=$mouth.'-01-01';
- $end=$mouth.'-12-31';
- $s= strtotime($start.'00:00:00');
- $e=strtotime($end.'23:59:59');
- $where['take_time'] = array('between',$s.",".$e);
- }
- if ($type=='月'){
- $time_array=$this->getthemonth($mouth);
- $start=$time_array['0'];
- $end=$time_array['1'];
- $s= strtotime($start.'00:00:00');
- $e=strtotime($end.'23:59:59');
- $where['take_time'] = array('between',$s.",".$e);
- }
- if ($type=='日'){
- $s= strtotime($mouth.'00:00:00');
- $e=strtotime($mouth.'23:59:59');
- $where['take_time'] = array('between',$s.",".$e);
- }
- $where['suser_id']=$suser_id;
- $where['status']=['in',['3','4']];
- $where1['take_time']=['neq',''];
- $get_order=StoreOrder::where($where)
- ->with(['member'])
- ->where($where1)
- ->field('id,order_id,take_time,mid,suser_id,pay_price,commission_price')
- ->order('take_time','desc')
- ->select();
- $get_num=StoreOrder::where($where)
- ->where($where1)
- ->field('sum(pay_price-commission_price) as order_price,count(*) as order_num')
- ->find();
- foreach ($get_order as $k=>$v){
- $get_order[$k]['take_date']=date('Y-m-d',$v['take_time']);
- }
- $this->result('SUCCESS', ['list'=>$get_order,'num'=>$get_num], 1);
- }
- }
|