CommonLogic.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic;
  20. use app\common\enum\PresellEnum;
  21. use app\common\enum\SeckillEnum;
  22. use app\common\enum\TeamEnum;
  23. use app\common\logic\BaseLogic;
  24. use app\common\model\BargainActivity;
  25. use app\common\model\BargainGoods;
  26. use app\common\model\Presell;
  27. use app\common\model\PresellGoods;
  28. use app\common\model\SeckillActivity;
  29. use app\common\model\SeckillGoods;
  30. use app\common\model\TeamActivity;
  31. use app\common\model\TeamGoods;
  32. use app\common\service\FileService;
  33. class CommonLogic extends BaseLogic
  34. {
  35. public static function getActivity($get, $type)
  36. {
  37. $where = [];
  38. if (!empty($get['keyword']) and $get['keyword']) {
  39. $where[] = ['name', 'like', '%'.$get['keyword'].'%'];
  40. }
  41. switch ($type) {
  42. case 'team':
  43. $count = (new TeamActivity())->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])->count();
  44. $lists = (new TeamActivity())
  45. ->field('id,name,start_time,end_time,status')
  46. ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])
  47. ->where($where)
  48. ->page($get['page_no'] ?? 1, $get['page_size'] ?? 25)
  49. ->select()
  50. ->toArray();
  51. foreach ($lists as &$item) {
  52. $item['status_text'] = TeamEnum::getActivityStatusDesc($item['status']);
  53. $item['start_time'] = date('Y-m-d H:i:s', $item['start_time']);
  54. $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  55. $item['goods_num'] = (new TeamGoods())->where(['team_id'=>$item['id']])->count();
  56. }
  57. return [
  58. 'count' => $count,
  59. 'lists' => $lists,
  60. 'page_no' => $get['page_no'] ?? 1,
  61. 'page_size' => $get['page_no'] ?? 25
  62. ];
  63. break;
  64. case 'seckill':
  65. $count = (new SeckillActivity()) ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])->count();
  66. $lists = (new SeckillActivity())
  67. ->field('id,name,start_time,end_time,status')
  68. ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])
  69. ->where($where)
  70. ->select()
  71. ->toArray();
  72. foreach ($lists as &$item) {
  73. $item['status_text'] = SeckillEnum::getSeckillStatusDesc($item['status']);
  74. $item['start_time'] = date('Y-m-d H:i:s', $item['start_time']);
  75. $item['end_time'] = date('Y-m-d H:i:s', $item['end_time']);
  76. $item['goods_num'] = (new SeckillGoods())->where(['seckill_id'=>$item['id']])->count();
  77. }
  78. return [
  79. 'count' => $count,
  80. 'lists' => $lists,
  81. 'page_no' => $get['page_no'] ?? 1,
  82. 'page_size' => $get['page_no'] ?? 25
  83. ];
  84. break;
  85. case 'bargain':
  86. $count = (new BargainActivity())->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])->count();
  87. $lists = (new BargainActivity())
  88. ->field('id,name,start_time,end_time,status')
  89. ->where(['status' => TeamEnum::TEAM_STATUS_CONDUCT])
  90. ->where($where)
  91. ->select()
  92. ->toArray();
  93. foreach ($lists as &$item) {
  94. $item['status_text'] = SeckillEnum::getSeckillStatusDesc($item['status']);
  95. $item['goods_num'] = (new BargainGoods())->where(['activity_id'=>$item['id']])->count();
  96. }
  97. return [
  98. 'count' => $count,
  99. 'lists' => $lists,
  100. 'page_no' => $get['page_no'] ?? 1,
  101. 'page_size' => $get['page_no'] ?? 25
  102. ];
  103. break;
  104. case "presell":
  105. $count = Presell::where('status', PresellEnum::STATUS_START)->count();
  106. $lists = Presell::where('status', PresellEnum::STATUS_START)
  107. ->where($where)
  108. ->append([ 'type_text', 'status_text', 'send_type_text', 'goods_num' ])
  109. ->select()
  110. ->toArray();
  111. return [
  112. 'count' => $count,
  113. 'lists' => $lists,
  114. 'page_no' => $get['page_no'] ?? 1,
  115. 'page_size' => $get['page_no'] ?? 25
  116. ];
  117. break;
  118. }
  119. return [];
  120. }
  121. /**
  122. * @notes 获取活动商品列表数据
  123. * @param $type
  124. * @param $activity_id
  125. * @param $keyword
  126. * @return array
  127. * @author 张无忌
  128. * @date 2021/10/9 18:41
  129. */
  130. public static function getActivityGoods($type, $activity_id, $keyword='')
  131. {
  132. switch ($type) {
  133. case 'team':
  134. $where = [];
  135. if ($keyword) {
  136. $where[] = ['G.name', 'like', '%'.$keyword.'%'];
  137. }
  138. $lists = (new TeamGoods())->alias('TG')
  139. ->field('TG.*,G.total_stock,G.name,G.image,G.min_price,G.max_price')
  140. ->join('goods G', 'G.id = TG.goods_id')
  141. ->where('TG.team_id', '=', intval($activity_id))
  142. ->where($where)
  143. ->select()->toArray();
  144. $data = [];
  145. foreach ($lists as $item) {
  146. $data[] = [
  147. 'id' => $item['id'],
  148. 'goods_id' => $item['goods_id'],
  149. 'name' => $item['name'],
  150. 'image' => FileService::getFileUrl($item['image']),
  151. 'total_stock' => $item['total_stock'],
  152. 'min_price' => $item['min_price'],
  153. 'max_price' => $item['max_price'],
  154. 'min_activity_price' => $item['min_team_price'],
  155. 'max_activity_price' => $item['max_team_price']
  156. ];
  157. }
  158. return $data;
  159. break;
  160. case 'seckill':
  161. $where = [];
  162. if ($keyword) {
  163. $where[] = ['G.name', 'like', '%'.$keyword.'%'];
  164. }
  165. $lists = (new SeckillGoods())->alias('SG')
  166. ->field('SG.*,G.total_stock,G.name,G.image,G.min_price,G.max_price')
  167. ->join('goods G', 'G.id = SG.goods_id')
  168. ->where('SG.seckill_id', '=', intval($activity_id))
  169. ->where($where)
  170. ->select()->toArray();
  171. $data = [];
  172. foreach ($lists as $item) {
  173. $data[] = [
  174. 'id' => $item['id'],
  175. 'goods_id' => $item['goods_id'],
  176. 'name' => $item['name'],
  177. 'image' => FileService::getFileUrl($item['image']),
  178. 'total_stock' => $item['total_stock'],
  179. 'min_price' => $item['min_price'],
  180. 'max_price' => $item['max_price'],
  181. 'min_activity_price' => $item['min_seckill_price'],
  182. 'max_activity_price' => $item['max_seckill_price'],
  183. ];
  184. }
  185. return $data;
  186. break;
  187. case 'bargain':
  188. $where = [];
  189. if ($keyword) {
  190. $where[] = ['G.name', 'like', '%'.$keyword.'%'];
  191. }
  192. $lists = (new BargainGoods())->alias('BG')
  193. ->field('BG.*,G.total_stock,G.name,G.image,G.min_price,G.max_price')
  194. ->join('goods G', 'G.id = BG.goods_id')
  195. ->where('BG.activity_id', '=', intval($activity_id))
  196. ->where($where)
  197. ->select()->toArray();
  198. $data = [];
  199. foreach ($lists as $item) {
  200. $data[] = [
  201. 'id' => $item['id'],
  202. 'goods_id' => $item['goods_id'],
  203. 'name' => $item['name'],
  204. 'image' => FileService::getFileUrl($item['image']),
  205. 'total_stock' => $item['total_stock'],
  206. 'min_price' => $item['min_price'],
  207. 'max_price' => $item['max_price'],
  208. 'min_activity_price' => $item['min_price'],
  209. 'max_activity_price' => $item['max_price']
  210. ];
  211. }
  212. return $data;
  213. break;
  214. case 'presell':
  215. $where = [];
  216. if ($keyword) {
  217. $where[] = ['G.name', 'like', '%'.$keyword.'%'];
  218. }
  219. $lists = (new PresellGoods())->alias('PG')
  220. ->field([ 'PG.*' ])
  221. ->with([ 'detail' ])
  222. ->join('goods G', 'G.id = PG.goods_id')
  223. ->where('PG.presell_id', '=', intval($activity_id))
  224. ->where($where)
  225. ->select()->toArray();
  226. $data = [];
  227. foreach ($lists as $item) {
  228. $data[] = [
  229. 'id' => $item['id'],
  230. 'goods_id' => $item['goods_id'],
  231. 'name' => $item['detail']['name'],
  232. 'image' => FileService::getFileUrl($item['detail']['image']),
  233. 'total_stock' => $item['detail']['total_stock'],
  234. 'min_price' => $item['detail']['min_price'],
  235. 'max_price' => $item['detail']['max_price'],
  236. 'min_activity_price' => $item['min_price'],
  237. 'max_activity_price' => $item['max_price'],
  238. ];
  239. }
  240. return $data;
  241. break;
  242. }
  243. return [];
  244. }
  245. }