ShopDay.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class ShopDay extends Base {
  5. public $table = 'shop_day';
  6. protected $validateName = 'ShopDay';
  7. public function updates(){
  8. $data = request()->post();
  9. $time = $data['time'];
  10. if(!$time){
  11. $this->error = '未选择开始结束时间';
  12. return false;
  13. }
  14. $times = explode(',',$time);
  15. if(count($times) != 2){
  16. $this->error = '未选择开始结束时间';
  17. return false;
  18. }
  19. $data['start'] = $times[0];
  20. $data['end'] = $times[1];
  21. unset($data['time']);
  22. $data['org_id'] = cur_org_id();
  23. $result = validate($this->validateName)->check($data,[],'');
  24. if(true !== $result){
  25. $this->error = validate($this->validateName)->getError();
  26. return false;
  27. }
  28. $id = $data['id'];
  29. unset($data['id']);
  30. if($id > 0){
  31. $data['update_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  33. }else{
  34. $data['create_time'] = date('Y-m-d H:i:s');
  35. $ret = $this->allowField(true)->save($data);
  36. }
  37. if(!$ret){
  38. $this->error = '操作失败';
  39. return false;
  40. }
  41. return true;
  42. }
  43. //获取今天和今天后的6天
  44. public function shopDate()
  45. {
  46. $frist=strtotime(date("Y-m-d"));
  47. $last=strtotime(date("Y-m-d"))+86400*6;
  48. $date=array();
  49. $array = ["日","一","二","三","四","五","六"];
  50. while($frist<=$last){
  51. $data['date']=date('Y-m-d',$last);
  52. $data['day']=date('d',$last);
  53. $data['week']=$array[date('w',$last)];
  54. array_unshift($date,$data);
  55. $last-=86400;
  56. }
  57. return $date;
  58. }
  59. public function cate($orgid){
  60. $cate = Db::name('shop_goods_cate')->where('org_id',$orgid)->field('id,name')->select();
  61. $goods = Db::name('shop_goods')
  62. ->where('org_id',$orgid)
  63. ->where('del',0)
  64. ->where('enable',1)
  65. ->field('id,title,price,img,description,cate_id')
  66. ->order('sort desc,id desc')
  67. ->select();
  68. foreach ($cate as $k=>$v){
  69. $gs = [];
  70. foreach ($goods as $kk=>$vv){
  71. if($vv['cate_id'] == $v['id']){
  72. $gs[] = $vv;
  73. }
  74. }
  75. $cate[$k]['goods'] = $gs;
  76. }
  77. return $cate;
  78. }
  79. public function cate_old($type,$orgid){
  80. $ret = Db::name('shop_day')
  81. ->where('org_id',$orgid)->where('id',$type)->value('goods');
  82. if(!$ret){
  83. return false;
  84. }
  85. $ids = explode(',',$ret);
  86. $goods = Db::name('shop_goods')
  87. ->where('org_id',$orgid)
  88. ->where('del',0)
  89. ->where('enable',1)
  90. ->where('id','in',$ids)
  91. ->field('id,title,price,img,description,cate_id')
  92. ->order('sort desc,id desc')
  93. ->select();
  94. foreach ($goods as $k=>$v){
  95. $goodscateid[]=$v['cate_id'];
  96. }
  97. $cateId = array_unique($goodscateid);
  98. $cate = Db::name('shop_goods_cate')
  99. ->where('id','in',$cateId)->field('id,name')
  100. ->select();
  101. foreach ($cate as $k=>$v){
  102. $gs = [];
  103. foreach ($goods as $kk=>$vv){
  104. if($vv['cate_id'] == $v['id']){
  105. $gs[] = $vv;
  106. }
  107. }
  108. $cate[$k]['goods'] = $gs;
  109. }
  110. return $cate;
  111. }
  112. public function goods($cate_id,$orgid){
  113. $ret = Db::name('shop_goods')
  114. ->field('id,title,price,img,description')
  115. ->where('cate_id',$cate_id)
  116. ->where('org_id',$orgid)
  117. ->where('del',0)
  118. ->where('enable',1)
  119. ->select();
  120. return $ret;
  121. }
  122. public function goods_old($type,$cate_id,$orgid){
  123. $ret = Db::name('shop_day')
  124. ->where('org_id',$orgid)->where('id',$type)->find();
  125. if(!$ret){
  126. return false;
  127. }
  128. $ids = explode(',',$ret['goods']);
  129. $ret = Db::name('shop_goods')
  130. ->field('id,title,price,img,description')
  131. ->where('cate_id',$cate_id)
  132. ->whereIn('id',$ids)
  133. ->where('del',0)
  134. ->where('enable',1)
  135. ->select();
  136. return $ret;
  137. }
  138. }