Good.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\api\controller;
  4. use app\api\model\ActGoodurl;
  5. use app\api\model\Brand;
  6. use app\api\model\Cat;
  7. use app\api\model\GoodSpec;
  8. use app\api\model\PlatformYouzan;
  9. use app\api\model\Unit;
  10. use app\txx\model\YzGood;
  11. use think\App;
  12. use think\facade\Validate;
  13. class Good extends Base
  14. {
  15. private $platform_id=[37,79];
  16. private $origin_img_host ='http://stock.api.wanyuhengtong.com';
  17. private $ssl_img_host ='https://image.wanyuhengtong.com';
  18. public function __construct(App $app) {
  19. parent::__construct($app);
  20. }
  21. public function list(){
  22. $param = $this->request->param(['page'=>1,'size'=>15,'good_name'=>''],'post','trim');
  23. $where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','in',$this->platform_id],['b.exam_status',
  24. '=',6]];
  25. $param['good_name']!=''??$where[]=['c.good_name','like',"%{$param['good_name']}%"];
  26. $actUrl= new ActGoodurl();
  27. $list = $actUrl->alias('a')
  28. ->leftJoin('platform_youzan b','a.act_good_id=b.id')
  29. ->leftJoin('good_basic c', 'c.spuCode=b.spuCode')
  30. ->where($where)
  31. ->field('b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,
  32. c.good_name,c.good_img,c.good_info_img,c.good_thumb_img,c.brand_id,c.cat_id,
  33. c.good_unit,a.addtime,a.updatetime,b.spuCode,b.sale_price,b.final_price')
  34. ->order('a.id desc')
  35. ->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
  36. foreach ($list->items() as $item){
  37. $item['brand_name'] =Brand::where('id',$item['brand_id'])->value('brand_name','');
  38. $item['good_unit'] =Unit::where('id',$item['good_unit'])->value('unit','');
  39. $item['cat_name'] =Cat::where('id',$item['cat_id'])->value('search','');
  40. $item['good_url'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('detail_url','');
  41. $item['origin_price'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('origin','');
  42. $item['spec_info'] =GoodSpec::where(['spuCode' => $item['spuCode'], 'is_del' => 0])->with(['spec',
  43. 'Spec_info'])->field('spec_id,spec_value_id')->select();
  44. }
  45. $this->success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
  46. }
  47. public function GoodInfo(){
  48. $param =$this->request->only(['skuCode'=>''],'post','trim');
  49. $valid =Validate::rule(['skuCode|商品上线编号'=>'require']);
  50. if($valid->check($param)==false)$this->error($valid->getError());
  51. $field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,
  52. a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
  53. a.good_unit,b.addtime,b.updatetime,a.spuCode, b.sale_price,b.final_price';
  54. $youzan = new PlatformYouzan();
  55. $info = $youzan
  56. ->alias('b')
  57. ->field($field)
  58. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  59. ->leftJoin('good_basic a', 'a.spuCode=b.spuCode')
  60. ->where(['b.skuCode'=>$param['skuCode'],'b.is_del'=>0])->findOrEmpty();
  61. if($info->isEmpty()) $this->error('商品数据未找到');
  62. $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
  63. $info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
  64. $info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
  65. $info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');;
  66. $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
  67. $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
  68. $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
  69. $info->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_img);
  70. $info->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_info_img);
  71. $info->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_thumb_img);
  72. $this->success('获取成功',$info);
  73. }
  74. }