|
@@ -0,0 +1,81 @@
|
|
|
+<?php
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\api\model\ActGoodUrl;
|
|
|
+use app\api\model\Brand;
|
|
|
+use app\api\model\Cat;
|
|
|
+use app\api\model\GoodSpec;
|
|
|
+use app\api\model\PlatformYouzan;
|
|
|
+use app\api\model\Unit;
|
|
|
+use app\model\Good as YzGood;
|
|
|
+use think\App;
|
|
|
+use think\facade\Validate;
|
|
|
+
|
|
|
+class Good extends Base
|
|
|
+{
|
|
|
+ private $platform_id=37;
|
|
|
+ private $origin_img_host ='http://stock.api.wanyuhengtong.com';
|
|
|
+ private $ssl_img_host ='https://image.wanyuhengtong.com';
|
|
|
+ public function __construct(App $app) {
|
|
|
+ parent::__construct($app);
|
|
|
+ }
|
|
|
+ public function list(){
|
|
|
+ $param = $this->request->param(['page'=>1,'size'=>15,'good_name'=>''],'post','trim');
|
|
|
+ $where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','=',$this->platform_id],['b.exam_status',
|
|
|
+ '=',6]];
|
|
|
+ $param['good_name']!=''??$where[]=['c.good_name','like',"%{$param['good_name']}%"];
|
|
|
+ $actUrl= new ActGoodurl();
|
|
|
+ $list = $actUrl->alias('a')
|
|
|
+ ->leftJoin('platform_youzan b','a.act_good_id=b.id')
|
|
|
+ ->leftJoin('good_basic c', 'c.spuCode=b.spuCode')
|
|
|
+ ->where($where)
|
|
|
+ ->field('b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,
|
|
|
+ c.good_name,c.good_img,c.good_info_img,c.good_thumb_img,c.brand_id,c.cat_id,
|
|
|
+ c.good_unit,a.addtime,a.updatetime,b.spuCode,b.sale_price,b.final_price')
|
|
|
+ ->order('a.id desc')
|
|
|
+ ->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
|
|
|
+ foreach ($list->items() as $item){
|
|
|
+ $item['brand_name'] =Brand::where('id',$item['brand_id'])->value('brand_name','');
|
|
|
+ $item['good_unit'] =Unit::where('id',$item['good_unit'])->value('unit','');
|
|
|
+ $item['cat_name'] =Cat::where('id',$item['cat_id'])->value('search','');
|
|
|
+ $item['good_url'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('detail_url','');
|
|
|
+ $item['origin_price'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('origin','');
|
|
|
+ $item['spec_info'] =GoodSpec::where(['spuCode' => $item['spuCode'], 'is_del' => 0])->with(['spec',
|
|
|
+ 'Spec_info'])->field('spec_id,spec_value_id')->select();
|
|
|
+ }
|
|
|
+ $this->success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function GoodInfo(){
|
|
|
+ $param =$this->request->only(['skuCode'=>''],'post','trim');
|
|
|
+ $valid =Validate::rule(['skuCode|商品上线编号'=>'require']);
|
|
|
+ if($valid->check($param)==false)$this->error($valid->getError());
|
|
|
+ $field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,
|
|
|
+ a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
|
|
|
+ a.good_unit,b.addtime,b.updatetime,a.spuCode, b.sale_price,b.final_price';
|
|
|
+ $youzan = new PlatformYouzan();
|
|
|
+ $info = $youzan
|
|
|
+ ->alias('b')
|
|
|
+ ->field($field)
|
|
|
+ //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
|
|
|
+ ->leftJoin('good_basic a', 'a.spuCode=b.spuCode')
|
|
|
+ ->where(['b.skuCode'=>$param['skuCode'],'b.is_del'=>0])->findOrEmpty();
|
|
|
+
|
|
|
+ if($info->isEmpty()) $this->error('商品数据未找到');
|
|
|
+
|
|
|
+ $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
|
|
|
+ $info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
|
|
|
+ $info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
|
|
|
+ $info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');;
|
|
|
+ $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
|
|
|
+ $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
|
|
|
+ $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
|
|
|
+
|
|
|
+ $info->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_img);
|
|
|
+ $info->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_info_img);
|
|
|
+ $info->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_thumb_img);
|
|
|
+ $this->success('获取成功',$info);
|
|
|
+ }
|
|
|
+}
|