Product.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\controller\api\warehouse;
  3. use app\common\model\store\order\StoreGroupOrder;
  4. use app\common\repositories\store\order\StoreGroupOrderRepository;
  5. use app\common\repositories\store\product\ProductRepository;
  6. use crmeb\basic\BaseController;
  7. use think\App;
  8. use think\facade\Db;
  9. use vipapis\marketplace\product\SuccessSku;
  10. class Product extends BaseController
  11. {
  12. protected $merId;
  13. protected $source;
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->source = $this->request->header('source');
  18. $this->merId = $this->request->header('merId');
  19. }
  20. //秒杀页面
  21. public function seckill()
  22. {
  23. try {
  24. [$page, $limit] = $this->getPage();
  25. $where = [
  26. 'ps.status' => 1,
  27. 'sp.is_show' => 1,
  28. 'merchant.status' => 1,
  29. 'sp.is_del' =>0
  30. ];
  31. if($this->source=='yhc' && $this->merId) { //一壶茶
  32. $where['ps.mer_id']=$this->merId;
  33. }
  34. $where2[]=array('ps.seckill_date','>=',date('Y-m-d'));
  35. $where2[]=array('ps.seckill_date','<',date('Y-m-d 23:59:59'));
  36. $lst = Db::name('product_seckill')
  37. -> alias('ps')
  38. -> join('store_product sp','ps.product_id = sp.product_id')
  39. ->leftJoin('merchant merchant','sp.mer_id=merchant.mer_id')
  40. ->field('ps.seckill_date,ps.ctime,ps.product_id,ps.status')
  41. ->where($where)
  42. ->where($where2)
  43. ->group('seckill_date')
  44. ->limit('3')
  45. ->select()
  46. ->toArray();
  47. // Db::name('log')->insert(['data'=>Db::name('log')->getLastSql()]);
  48. $d = date('d', time());
  49. $m = date('m', time());
  50. $newtime = date('H', time());
  51. foreach ($lst as $k => &$v) {
  52. $date = $v['seckill_date'];
  53. $vd = date('d', strtotime($v['seckill_date']));
  54. $vm = date('m', strtotime($v['seckill_date']));
  55. $vtime = date('H', strtotime($v['seckill_date']));
  56. if ($d < $vd||$m<$vm) {
  57. $v['status']=2;
  58. $seckill_date = $vd . '日' . $vtime . ":00" . '开始';
  59. $v['product_data'] = $this->seckill_product($date, $page, $limit,'2');
  60. } else {
  61. if ($newtime < $vtime) {
  62. if ($d > $vd) {
  63. $v['status']=3;
  64. $seckill_date = $vd . '日' . $vtime . ":00" . '已结束';
  65. $v['product_data'] = $this->seckill_product($date, $page, $limit,'3');
  66. } else {
  67. $v['status']=2;
  68. $seckill_date = $vtime . ":00即将开始";
  69. $v['product_data'] = $this->seckill_product($date, $page, $limit,'2');
  70. }
  71. } else {
  72. if ($d > $vd||$newtime > $vtime) {
  73. $seckill_date = $vd . '日' . $vtime . ":00" . '已结束';
  74. $v['product_data'] = $this->seckill_product($date, $page, $limit,'3');
  75. } else {
  76. $seckill_date = $vtime . ":00抢购中";
  77. $v['status']=1;
  78. $v['product_data'] = $this->seckill_product($date, $page, $limit,'1');
  79. }
  80. }
  81. }
  82. $v['seckill_date'] = $seckill_date;
  83. }
  84. }catch (\Exception $exception){
  85. Db::name('log')->insert(['data'=>'秒杀页面错误:'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  86. }
  87. return app('json')->success($lst);
  88. }
  89. //秒杀商品列表
  90. public function seckill_product($time,$page,$limit,$type)
  91. {
  92. $where=[
  93. 'ps.status'=>1,
  94. 'ps.seckill_date'=>$time,
  95. 'merchant.status' => 1,
  96. 'sp.is_del' =>0
  97. ];
  98. if($this->source=='yhc' && $this->merId) { //一壶茶
  99. $where['ps.mer_id']=$this->merId;
  100. }
  101. $product_data=Db::name('product_seckill')
  102. ->alias('ps')
  103. ->field('ps.product_id')
  104. ->join('store_product sp','sp.product_id=ps.product_id')
  105. ->leftJoin('merchant merchant','sp.mer_id=merchant.mer_id')
  106. ->where('sp.is_show',1)
  107. // ->where('store_product.is_hide',1)
  108. ->where($where)->page($page,$limit)->select()->toArray();
  109. // $ProductRepository=app() -> make(ProductRepository::class);
  110. foreach ($product_data as $k=>&$vv) {
  111. $product_id=$vv['product_id'];
  112. $vv= Db::name('store_product')->where('product_id', $product_id)->field('mer_id,product_id,store_name,image,ot_price,dc_price as seckill_price,spu_id')->find();
  113. if (!empty($vv)) {
  114. $vv['seckill_price'] = Db::name('store_product_attr_value')->where('product_id', $product_id)->value('dacang_price');
  115. $mer_fanyongbili = merchantConfig($vv['mer_id'], 'base_commission');
  116. //如果商户返佣比例设置的是0怎查系统设设置的分佣比例
  117. if ($mer_fanyongbili == 0) {
  118. $mer_fanyongbili = merchantConfig(0, 'extension_one_rate');
  119. }
  120. $mer_fanyongbili=bcdiv($mer_fanyongbili, '100', 3);
  121. $vv['ot_price']=set_price_rtrim($vv['ot_price']);
  122. $vv['seckill_price']=set_price_rtrim($vv['seckill_price']);
  123. if (!empty($vv['spu_id'])){
  124. $gong_pension=Db::name("store_product_attr_value")->where("product_id",$vv['product_id']) -> order("cost_price asc")->value("gong_pension");
  125. $vv['yanglao']=set_price_rtrim($gong_pension);
  126. }else{
  127. $vv['yanglao']= bcmul(bcmul($vv['seckill_price'],$mer_fanyongbili,2),'0.5',2);;//养老金
  128. $vv['yanglao']=set_price_rtrim($vv['yanglao']);
  129. }
  130. }
  131. if($type==1){
  132. $vv['status']=1;
  133. $vv['img_text']='抢购中';
  134. }elseif($type==2){
  135. $vv['status']=2;
  136. $vv['img_text']='大仓秒杀';
  137. }else{
  138. $vv['status']=3;
  139. $vv['img_text']='已结束';
  140. }
  141. }
  142. return $product_data;
  143. }
  144. public function vip_one_yuan_product()
  145. {
  146. $data=Db::name('store_product')->field('product_id,store_name,image,price')->where('product_id',systemConfig('vip_one_yuan_product'))->find();
  147. if($data)
  148. return app('json')->success($data);
  149. return app('json')->fail('暂无数据');
  150. }
  151. public function vip_exclusive_product()
  152. {
  153. $data=Db::name('store_product')->field('store_name,image,price,product_id')->where('product_id',systemConfig('vip_exclusive_product'))->find();
  154. return app('json')->success($data);
  155. }
  156. //秒杀结束定时任务
  157. public function close_seckill()
  158. {
  159. $now_time=date('Y-m-d H',time());
  160. $lst=Db::name('product_seckill')->where('seckill_date','<',$now_time)->where('status',1)->select()->toArray();
  161. $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
  162. foreach ($lst as $k=>$v){
  163. Db::name('product_seckill')->where('id',$v['id'])->update(['status'=>2]);
  164. $storeGroupOrderRepository->ProductOutCancel($v['product_id']);
  165. $product_attr_value = Db::name('store_product_attr_value')->where('product_id', $v['product_id'])->find();
  166. if($product_attr_value['stock']==0){
  167. Db::name('store_product')->where('product_id', $v['product_id'])->update([
  168. 'is_show' => 0,
  169. 'is_hide' => 0,
  170. 'seckill' => 0
  171. ]);
  172. }else{
  173. Db::name('store_product')->where('product_id', $v['product_id'])->update([
  174. 'is_show' => 1,
  175. 'is_hide' => 0,
  176. 'seckill' => 0
  177. ]);
  178. }
  179. }
  180. }
  181. public function chenckproduct_isdaCang($id)
  182. {
  183. //商品信息
  184. $is_dacang=Db::name('store_product')->where('product_id',$id)->find();
  185. if($is_dacang){
  186. if($is_dacang['type']==5){
  187. $is_dacang=1;
  188. }else{
  189. $is_dacang=0;
  190. }
  191. }
  192. return app('json')->success($is_dacang);
  193. }
  194. }