| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- namespace app\controller\api\warehouse;
- use app\common\model\store\order\StoreGroupOrder;
- use app\common\repositories\store\order\StoreGroupOrderRepository;
- use app\common\repositories\store\product\ProductRepository;
- use crmeb\basic\BaseController;
- use think\App;
- use think\facade\Db;
- use vipapis\marketplace\product\SuccessSku;
- class Product extends BaseController
- {
- protected $merId;
- protected $source;
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->source = $this->request->header('source');
- $this->merId = $this->request->header('merId');
- }
- //秒杀页面
- public function seckill()
- {
- try {
- [$page, $limit] = $this->getPage();
- $where = [
- 'ps.status' => 1,
- 'sp.is_show' => 1,
- 'merchant.status' => 1,
- 'sp.is_del' =>0
- ];
- if($this->source=='yhc' && $this->merId) { //一壶茶
- $where['ps.mer_id']=$this->merId;
- }
- $where2[]=array('ps.seckill_date','>=',date('Y-m-d'));
- $where2[]=array('ps.seckill_date','<',date('Y-m-d 23:59:59'));
- $lst = Db::name('product_seckill')
- -> alias('ps')
- -> join('store_product sp','ps.product_id = sp.product_id')
- ->leftJoin('merchant merchant','sp.mer_id=merchant.mer_id')
- ->field('ps.seckill_date,ps.ctime,ps.product_id,ps.status')
- ->where($where)
- ->where($where2)
- ->group('seckill_date')
- ->limit('3')
- ->select()
- ->toArray();
- // Db::name('log')->insert(['data'=>Db::name('log')->getLastSql()]);
- $d = date('d', time());
- $m = date('m', time());
- $newtime = date('H', time());
- foreach ($lst as $k => &$v) {
- $date = $v['seckill_date'];
- $vd = date('d', strtotime($v['seckill_date']));
- $vm = date('m', strtotime($v['seckill_date']));
- $vtime = date('H', strtotime($v['seckill_date']));
- if ($d < $vd||$m<$vm) {
- $v['status']=2;
- $seckill_date = $vd . '日' . $vtime . ":00" . '开始';
- $v['product_data'] = $this->seckill_product($date, $page, $limit,'2');
- } else {
- if ($newtime < $vtime) {
- if ($d > $vd) {
- $v['status']=3;
- $seckill_date = $vd . '日' . $vtime . ":00" . '已结束';
- $v['product_data'] = $this->seckill_product($date, $page, $limit,'3');
- } else {
- $v['status']=2;
- $seckill_date = $vtime . ":00即将开始";
- $v['product_data'] = $this->seckill_product($date, $page, $limit,'2');
- }
- } else {
- if ($d > $vd||$newtime > $vtime) {
- $seckill_date = $vd . '日' . $vtime . ":00" . '已结束';
- $v['product_data'] = $this->seckill_product($date, $page, $limit,'3');
- } else {
- $seckill_date = $vtime . ":00抢购中";
- $v['status']=1;
- $v['product_data'] = $this->seckill_product($date, $page, $limit,'1');
- }
- }
- }
- $v['seckill_date'] = $seckill_date;
- }
- }catch (\Exception $exception){
- Db::name('log')->insert(['data'=>'秒杀页面错误:'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
- }
- return app('json')->success($lst);
- }
- //秒杀商品列表
- public function seckill_product($time,$page,$limit,$type)
- {
- $where=[
- 'ps.status'=>1,
- 'ps.seckill_date'=>$time,
- 'merchant.status' => 1,
- 'sp.is_del' =>0
- ];
- if($this->source=='yhc' && $this->merId) { //一壶茶
- $where['ps.mer_id']=$this->merId;
- }
- $product_data=Db::name('product_seckill')
- ->alias('ps')
- ->field('ps.product_id')
- ->join('store_product sp','sp.product_id=ps.product_id')
- ->leftJoin('merchant merchant','sp.mer_id=merchant.mer_id')
- ->where('sp.is_show',1)
- // ->where('store_product.is_hide',1)
- ->where($where)->page($page,$limit)->select()->toArray();
- // $ProductRepository=app() -> make(ProductRepository::class);
- foreach ($product_data as $k=>&$vv) {
- $product_id=$vv['product_id'];
- $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();
- if (!empty($vv)) {
- $vv['seckill_price'] = Db::name('store_product_attr_value')->where('product_id', $product_id)->value('dacang_price');
- $mer_fanyongbili = merchantConfig($vv['mer_id'], 'base_commission');
- //如果商户返佣比例设置的是0怎查系统设设置的分佣比例
- if ($mer_fanyongbili == 0) {
- $mer_fanyongbili = merchantConfig(0, 'extension_one_rate');
- }
- $mer_fanyongbili=bcdiv($mer_fanyongbili, '100', 3);
- $vv['ot_price']=set_price_rtrim($vv['ot_price']);
- $vv['seckill_price']=set_price_rtrim($vv['seckill_price']);
- if (!empty($vv['spu_id'])){
- $gong_pension=Db::name("store_product_attr_value")->where("product_id",$vv['product_id']) -> order("cost_price asc")->value("gong_pension");
- $vv['yanglao']=set_price_rtrim($gong_pension);
- }else{
- $vv['yanglao']= bcmul(bcmul($vv['seckill_price'],$mer_fanyongbili,2),'0.5',2);;//养老金
- $vv['yanglao']=set_price_rtrim($vv['yanglao']);
- }
- }
- if($type==1){
- $vv['status']=1;
- $vv['img_text']='抢购中';
- }elseif($type==2){
- $vv['status']=2;
- $vv['img_text']='大仓秒杀';
- }else{
- $vv['status']=3;
- $vv['img_text']='已结束';
- }
- }
- return $product_data;
- }
- public function vip_one_yuan_product()
- {
- $data=Db::name('store_product')->field('product_id,store_name,image,price')->where('product_id',systemConfig('vip_one_yuan_product'))->find();
- if($data)
- return app('json')->success($data);
- return app('json')->fail('暂无数据');
- }
- public function vip_exclusive_product()
- {
- $data=Db::name('store_product')->field('store_name,image,price,product_id')->where('product_id',systemConfig('vip_exclusive_product'))->find();
- return app('json')->success($data);
- }
- //秒杀结束定时任务
- public function close_seckill()
- {
- $now_time=date('Y-m-d H',time());
- $lst=Db::name('product_seckill')->where('seckill_date','<',$now_time)->where('status',1)->select()->toArray();
- $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
- foreach ($lst as $k=>$v){
- Db::name('product_seckill')->where('id',$v['id'])->update(['status'=>2]);
- $storeGroupOrderRepository->ProductOutCancel($v['product_id']);
- $product_attr_value = Db::name('store_product_attr_value')->where('product_id', $v['product_id'])->find();
- if($product_attr_value['stock']==0){
- Db::name('store_product')->where('product_id', $v['product_id'])->update([
- 'is_show' => 0,
- 'is_hide' => 0,
- 'seckill' => 0
- ]);
- }else{
- Db::name('store_product')->where('product_id', $v['product_id'])->update([
- 'is_show' => 1,
- 'is_hide' => 0,
- 'seckill' => 0
- ]);
- }
- }
- }
- public function chenckproduct_isdaCang($id)
- {
- //商品信息
- $is_dacang=Db::name('store_product')->where('product_id',$id)->find();
- if($is_dacang){
- if($is_dacang['type']==5){
- $is_dacang=1;
- }else{
- $is_dacang=0;
- }
- }
- return app('json')->success($is_dacang);
- }
- }
|