TxGood.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\controller;
  4. use app\admin\model\Brand;
  5. use app\admin\model\Cat;
  6. use app\admin\model\PlatformYouzan;
  7. use app\admin\model\Unit;
  8. use app\report\model\GoodSpec;
  9. use app\txx\model\ActGoodurl;
  10. use app\txx\model\YzGood;
  11. use think\App;
  12. use think\facade\Validate;
  13. class TxGood extends Base
  14. {
  15. private $platform_id=[37,79];
  16. public $origin_img_host ='http://stock.api.wanyuhengtong.com';
  17. public $ssl_img_host ='https://image.wanyuhengtong.com';
  18. public function __construct(App $app) {
  19. parent::__construct($app);
  20. }
  21. /**
  22. * 1. 十万订单每秒热点数据架构如何优化
  23. * 2. Redis集群崩溃时如何保证秒杀系统高可用
  24. * 3. Redis主从切换导致库存同步异常以及超卖问题
  25. * 4. 秒杀链路中Redis与MQ如何保证事务一致性
  26. * 5. 线上MQ百万秒杀订单积压如何优化
  27. * 6. 如何用Redis高效实现12306的复杂售票业务
  28. * 7. 新浪微博突发事件如何做好Redis缓存的高可用
  29. * 8. 高并发场景缓存穿透&失效&雪崩如何解决
  30. * 9. Redis集群架构如何抗住12306与双11的洪峰流量
  31. * 10. Redis缓存与数据库双写不一致如何解决
  32. * 11. 双十一亿级用户日活统计如何用Redis快速计算
  33. * 12. 双十一电商推荐系统如何用Redis实现
  34. * 13. 日均百亿级微信红包系统如何架构
  35. * 14. 类似微信的社交App朋友圈关注模型如何设计实现
  36. * 15. 美团单车如何基于Redis快速找到附近的车
  37. * 16. Redis分布式锁主从架构锁失效问题如何解决
  38. * 17. 超大并发的分布式锁架构该如何设计
  39. * 18. Redis底层ZSet跳表是如何设计与实现的
  40. * 19. Redis底层ZSet实现压缩列表和跳表如何选择
  41. * 20. Redis6.0多线程模型比单线程优化在哪里了
  42. */
  43. public function AddCouponUrl(){
  44. $param = $this->request->param(["skuCode"=>"","coupon_url"=>""],"post","trim");
  45. $valid =Validate::rule(["skuCode|商品上线编号"=>"require","coupon_url|商品优惠券链接"=>"require"]);
  46. if($valid->check($param)==false)$this->error($valid->getError());
  47. $youzan = new PlatformYouzan();
  48. $info = $youzan->where(["skuCode"=>$param['skuCode'],"is_del"=>0])->findOrEmpty();
  49. if($info->isEmpty())$this->error("未找到商品信息");
  50. if($info->exam_status!=6)$this->error("商品未上线");
  51. $actUrl= new ActGoodurl();
  52. $isT = $actUrl->where(["act_good_id"=>$info->id,"is_del"=>0])->findOrEmpty();
  53. if($isT->isEmpty()){
  54. $data=[
  55. "act_good_url"=>$param['coupon_url'],
  56. "act_good_id"=>$info->id,
  57. "apply_id"=>$this->uid,
  58. "apply_name"=>$this->uname,
  59. ];
  60. }else{
  61. $data=[
  62. 'act_good_url'=>$param['coupon_url'],
  63. 'apply_id'=>$this->uid,
  64. 'apply_name'=>$this->uname,
  65. ];
  66. }
  67. $up=$isT->save($data);
  68. $up?$this->success("链接上传成功"):$this->error("链接上传失败");
  69. }
  70. public function list(){
  71. $param = $this->request->param(["page"=>1,"size"=>15,"good_name"=>""],'post','trim');
  72. $where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','in',$this->platform_id],['b.exam_status',
  73. '=',6]];
  74. $param['good_name']!=''??$where[]=["c.good_name","like","%{$param['good_name']}%"];
  75. $actUrl= new ActGoodurl();
  76. $list = $actUrl->alias("a")
  77. ->leftJoin("platform_youzan b","a.act_good_id=b.id")
  78. ->leftJoin('good_basic c', 'c.spuCode=b.spuCode')
  79. ->where($where)
  80. ->field("b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,b.desc,
  81. c.good_name,c.good_img,c.good_info_img,c.good_thumb_img,c.brand_id,c.cat_id,
  82. c.good_unit,a.addtime,a.updatetime,b.spuCode,b.sale_price,b.final_price")
  83. ->order("a.id desc")
  84. ->paginate(["list_rows"=>$param['size'],"page"=>$param["page"]]);
  85. foreach ($list->items() as $item){
  86. $item['brand_name'] =Brand::where("id",$item['brand_id'])->value("brand_name",'');
  87. $item['good_unit'] =Unit::where("id",$item['good_unit'])->value("unit",'');
  88. $item['cat_name'] =Cat::where("id",$item['cat_id'])->value("search",'');
  89. $item['good_url'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('detail_url','');
  90. $item['origin_price'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('origin','');
  91. $item['spec_info'] =GoodSpec::where(["spuCode" => $item['spuCode'], "is_del" => 0])->with(["spec",
  92. "Spec_info"])->field("spec_id,spec_value_id")->select();
  93. }
  94. $this->success('获取成功',["list"=>$list->items(),"count"=>$list->total()]);
  95. }
  96. public function GoodInfo(){
  97. $param =$this->request->only(['skuCode'=>''],'post','trim');
  98. $valid =Validate::rule(['skuCode|商品上线编号'=>'require']);
  99. if($valid->check($param)==false)$this->error($valid->getError());
  100. $field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,b.desc,
  101. a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
  102. a.good_unit,b.addtime,b.updatetime,a.spuCode, b.sale_price,b.final_price';
  103. $youzan = new PlatformYouzan();
  104. $info = $youzan
  105. ->alias('b')
  106. ->field($field)
  107. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  108. ->leftJoin('good_basic a', 'a.spuCode=b.spuCode')
  109. ->where(['b.skuCode'=>$param['skuCode'],'b.is_del'=>0])->findOrEmpty();
  110. if($info->isEmpty()) $this->error('商品数据未找到');
  111. $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
  112. $info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
  113. $info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
  114. $info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');
  115. $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
  116. $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
  117. $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
  118. $info->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_img);
  119. $info->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_info_img);
  120. $info->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_thumb_img);
  121. $this->success('获取成功',$info);
  122. }
  123. }