Queue.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <?php
  2. namespace app\common\logic;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 逻辑层模型
  13. */
  14. class Queue
  15. {
  16. /**
  17. * 添加会员积分
  18. * @param unknown $member_info
  19. */
  20. public function addPoint($member_info)
  21. {
  22. $points_model = model('points');
  23. $points_model->savePointslog('login', array(
  24. 'pl_memberid' => $member_info['member_id'], 'pl_membername' => $member_info['member_name']
  25. ), true);
  26. return ds_callback(true);
  27. }
  28. /**
  29. * 添加会员经验值
  30. * @param unknown $member_info
  31. */
  32. public function addExppoint($member_info)
  33. {
  34. $exppoints_model = model('exppoints');
  35. $exppoints_model->saveExppointslog('login', array(
  36. 'explog_memberid' => $member_info['member_id'], 'explog_membername' => $member_info['member_name']
  37. ), true);
  38. return ds_callback(true);
  39. }
  40. /**
  41. * 更新抢购信息
  42. * @param unknown $groupbuy_info
  43. * @throws Exception
  44. */
  45. public function editGroupbuySaleCount($groupbuy_info)
  46. {
  47. $groupbuy_model = model('groupbuy');
  48. $data = array();
  49. $data['groupbuy_buyer_count'] = Db::raw('groupbuy_buyer_count+1');
  50. $data['groupbuy_buy_quantity'] = Db::raw('groupbuy_buy_quantity+' . $groupbuy_info['quantity']);
  51. $update = $groupbuy_model->editGroupbuy($data, array('groupbuy_id' => $groupbuy_info['groupbuy_id']));
  52. if (!$update) {
  53. return ds_callback(false, '更新抢购信息失败groupbuy_id:' . $groupbuy_info['groupbuy_id']);
  54. } else {
  55. return ds_callback(true);
  56. }
  57. }
  58. /**
  59. * 根据商品id更新促销价格
  60. *
  61. * @param int /array $goods_commonid
  62. * @return boolean
  63. */
  64. public function updateGoodsPromotionPriceByGoodsId($goods_id)
  65. {
  66. if (!is_array($goods_id)) {
  67. $goods_id = (string)$goods_id;
  68. }
  69. $condition = array();
  70. $condition[] = array('goods_id', 'in', $goods_id);
  71. $update = model('goods')->editGoodsPromotionPrice($condition);
  72. if (!$update) {
  73. return ds_callback(false, '根据商品ID更新促销价格失败');
  74. } else {
  75. return ds_callback(true);
  76. }
  77. }
  78. /**
  79. * 根据商品公共id更新促销价格
  80. *
  81. * @param int /array $goods_commonid
  82. * @return boolean
  83. */
  84. public function updateGoodsPromotionPriceByGoodsCommonId($goods_commonid)
  85. {
  86. if (!is_array($goods_commonid)) {
  87. $goods_commonid = (string)$goods_commonid;
  88. }
  89. $condition = array();
  90. $condition[] = array('goods_commonid', 'in', $goods_commonid);
  91. $update = model('goods')->editGoodsPromotionPrice($condition);
  92. if (!$update) {
  93. return ds_callback(false, '根据商品公共id更新促销价格失败');
  94. } else {
  95. return ds_callback(true);
  96. }
  97. }
  98. /**
  99. * 发送店铺消息
  100. */
  101. public function sendStoremsg($param)
  102. {
  103. $send = new \sendmsg\sendStoremsg();
  104. $send->set('code', $param['code']);
  105. $send->set('store_id', $param['store_id']);
  106. $send->send($param['param'], isset($param['weixin_param']) ? $param['weixin_param'] : array(), isset($param['ali_param']) ? $param['ali_param'] : array(), isset($param['ten_param']) ? $param['ten_param'] : array());
  107. return ds_callback(true);
  108. }
  109. /**
  110. * 发送会员消息
  111. */
  112. public function sendMemberMsg($param)
  113. {
  114. $send = new \sendmsg\sendMemberMsg();
  115. $send->set('code', $param['code']);
  116. $send->set('member_id', $param['member_id']);
  117. if (!empty($param['number']['mobile']))
  118. $send->set('mobile', $param['number']['mobile']);
  119. if (!empty($param['number']['email']))
  120. $send->set('email', $param['number']['email']);
  121. $send->send($param['param'], isset($param['weixin_param']) ? $param['weixin_param'] : array(), isset($param['ali_param']) ? $param['ali_param'] : array(), isset($param['ten_param']) ? $param['ten_param'] : array());
  122. return ds_callback(true);
  123. }
  124. /**
  125. * 清理特殊商品促销信息
  126. */
  127. public function clearSpecialGoodsPromotion($param)
  128. {
  129. // 抢购
  130. model('groupbuy')->delGroupbuy(array('goods_commonid' => $param['goods_commonid']));
  131. // 显示折扣
  132. $condition = array();
  133. $condition[] = array('goods_id', 'in', $param['goodsid_array']);
  134. model('pxianshigoods')->delXianshigoods($condition);
  135. // 优惠套装
  136. $condition = array();
  137. $condition[] = array('goods_id', 'in', $param['goodsid_array']);
  138. model('pbundling')->delBundlingGoods($condition);
  139. // 更新促销价格
  140. model('goods')->editGoods(array('goods_promotion_price' => Db::raw('goods_price'), 'goods_promotion_type' => 0), array('goods_commonid' => $param['goods_commonid']));
  141. return ds_callback(true);
  142. }
  143. /**
  144. * 删除(买/卖家)订单全部数量缓存
  145. * @param array $data 订单信息
  146. * @return boolean
  147. */
  148. public function delOrderCountCache($order_info)
  149. {
  150. if (empty($order_info))
  151. return ds_callback(true);
  152. $order_model = model('order');
  153. if (isset($order_info['order_id'])) {
  154. $order_info = $order_model->getOrderInfo(array('order_id' => $order_info['order_id']), array(), 'buyer_id,store_id');
  155. }
  156. if (isset($order_info['buyer_id'])) {
  157. $order_model->delOrderCountCache('buyer', $order_info['buyer_id']);
  158. }
  159. if (isset($order_info['store_id'])) {
  160. $order_model->delOrderCountCache('store', $order_info['store_id']);
  161. }
  162. return ds_callback(true);
  163. }
  164. /**
  165. * 发送提货码短信消息
  166. */
  167. public function sendPickupcode($param)
  168. {
  169. $order_common_info = model('order')->getOrdercommonInfo(array('order_id' => $param['order_id']), 'reciver_info');
  170. if ($order_common_info) {
  171. $order_common_info['reciver_info'] = @unserialize($order_common_info['reciver_info']);
  172. $tpl_info = model('mailtemplates')->getTplInfo(array('mailmt_code' => 'send_pickup_code'));
  173. $data = array();
  174. $data['pickup_code'] = $param['pickup_code'];
  175. $ten_data = array($data['pickup_code']);
  176. $message = ds_replace_text($tpl_info['mailmt_content'], $data);
  177. $smslog_param = array(
  178. 'ali_template_code' => $tpl_info['ali_template_code'],
  179. 'ali_template_param' => $data,
  180. 'ten_template_code' => $tpl_info['ten_template_code'],
  181. 'ten_template_param' => $ten_data,
  182. 'message' => $message,
  183. );
  184. $result = model('smslog')->sendSms($order_common_info['reciver_info']['mob_phone'], $smslog_param);
  185. if (!$result) {
  186. return ds_callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
  187. } else {
  188. return ds_callback(true);
  189. }
  190. } else {
  191. return ds_callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
  192. }
  193. }
  194. /**
  195. * 生成卡密代金券
  196. */
  197. public function build_pwdvoucher($t_id)
  198. {
  199. $t_id = intval($t_id);
  200. if ($t_id <= 0) {
  201. return ds_callback(false, '参数错误');
  202. }
  203. $voucher_model = model('voucher');
  204. //查询代金券详情
  205. $where = array();
  206. $where[] = array('vouchertemplate_id', '=', $t_id);
  207. $gettype_arr = $voucher_model->getVoucherGettypeArray();
  208. $where[] = array('vouchertemplate_gettype', '=', $gettype_arr['pwd']['sign']);
  209. $where[] = array('vouchertemplate_isbuild', '=', 0);
  210. $where[] = array('vouchertemplate_state', '=', 1);
  211. $t_info = $voucher_model->getVouchertemplateInfo($where);
  212. $t_total = intval($t_info['vouchertemplate_total']);
  213. if ($t_total <= 0) {
  214. return ds_callback(false, '代金券模板信息错误');
  215. }
  216. while ($t_total > 0) {
  217. $is_succ = false;
  218. $insert_arr = array();
  219. $step = $t_total > 1000 ? 1000 : $t_total;
  220. for ($t = 0; $t < $step; $t++) {
  221. $voucher_code = $voucher_model->getVoucherCode(0);
  222. if (!$voucher_code) {
  223. continue;
  224. }
  225. $voucher_pwd_arr = $voucher_model->createVoucherPwd($t_info['vouchertemplate_id']);
  226. if (!$voucher_pwd_arr) {
  227. continue;
  228. }
  229. $tmp = array();
  230. $tmp['voucher_code'] = $voucher_code;
  231. $tmp['vouchertemplate_id'] = $t_info['vouchertemplate_id'];
  232. $tmp['voucher_title'] = $t_info['vouchertemplate_title'];
  233. $tmp['voucher_desc'] = $t_info['vouchertemplate_desc'];
  234. $tmp['voucher_startdate'] = $t_info['vouchertemplate_startdate'];
  235. $tmp['voucher_enddate'] = $t_info['vouchertemplate_enddate'];
  236. $tmp['voucher_price'] = $t_info['vouchertemplate_price'];
  237. $tmp['voucher_limit'] = $t_info['vouchertemplate_limit'];
  238. $tmp['voucher_store_id'] = $t_info['vouchertemplate_store_id'];
  239. $tmp['voucher_state'] = 1;
  240. $tmp['voucher_activedate'] = TIMESTAMP;
  241. $tmp['voucher_owner_id'] = 0;
  242. $tmp['voucher_owner_name'] = '';
  243. $tmp['voucher_order_id'] = 0;
  244. $tmp['voucher_pwd'] = $voucher_pwd_arr[0]; //md5
  245. $tmp['voucher_pwd2'] = $voucher_pwd_arr[1];
  246. $insert_arr[] = $tmp;
  247. $t_total--;
  248. }
  249. $result = $voucher_model->addVoucherBatch($insert_arr);
  250. if ($result && $is_succ == false) {
  251. $is_succ = true;
  252. }
  253. }
  254. //更新代金券模板
  255. if ($is_succ) {
  256. $voucher_model->editVouchertemplate(array('vouchertemplate_id' => $t_info['vouchertemplate_id']), array('vouchertemplate_isbuild' => 1));
  257. return ds_callback(true);
  258. } else {
  259. return ds_callback(false);
  260. }
  261. }
  262. /**
  263. * 上架
  264. *
  265. * @param int $goods_commonid
  266. */
  267. public function editProducesOnline($goods_commonid)
  268. {
  269. $condition = array(array('goods_commonid', '=', $goods_commonid));
  270. $update = model('goods')->editProducesOnline($condition);
  271. if (!$update) {
  272. return ds_callback(false);
  273. }
  274. return ds_callback(true);
  275. }
  276. /**
  277. * 优惠套装过期
  278. *
  279. * @param int $store_id
  280. */
  281. public function editBundlingQuotaClose($store_id)
  282. {
  283. $pbundling_model = model('pbundling');
  284. if (intval(config('ds_config.promotion_bundling_price')) != 0) {
  285. //如果没有购买过套餐,则将之前添加的优惠组合关闭
  286. Db::name('pbundling')->alias('pbundling')->join('pbundlingquota pbundlingquota', 'pbundling.store_id = pbundlingquota.store_id', 'LEFT')->where('pbundlingquota.store_id', null)->update(array('bl_state' => $pbundling_model::STATE0));
  287. }
  288. $condition = array(array('store_id', '=', $store_id));
  289. $update = $pbundling_model->editBundlingQuotaClose($condition);
  290. if (!$update) {
  291. return ds_callback(false);
  292. }
  293. return ds_callback(true);
  294. }
  295. /**
  296. * 推荐展位过期
  297. *
  298. * @param int $store_id
  299. */
  300. public function editBoothClose($store_id)
  301. {
  302. $pbooth_model = model('pbooth');
  303. if (intval(config('ds_config.promotion_bundling_price')) != 0) {
  304. //如果没有购买过套餐,则将之前添加的优惠组合关闭
  305. Db::name('pboothgoods')->alias('pboothgoods')->join('pboothquota pboothquota', 'pboothgoods.store_id = pboothquota.store_id', 'LEFT')->where('pboothquota.store_id', null)->update(array('boothgoods_state' => $pbooth_model::STATE0));
  306. }
  307. $condition = array(array('store_id', '=', $store_id));
  308. $update = $pbooth_model->editBoothClose($condition);
  309. if (!$update) {
  310. return ds_callback(false);
  311. }
  312. return ds_callback(true);
  313. }
  314. /**
  315. * 抢购开始更新商品促销价格
  316. *
  317. * @param int $goods_commonid
  318. */
  319. public function editGoodsGroupbuyPrice($goods_commonid)
  320. {
  321. $condition = array();
  322. $condition[] = array('goods_commonid', '=', $goods_commonid);
  323. $condition[] = array('groupbuy_starttime', '<', TIMESTAMP);
  324. $condition[] = array('groupbuy_endtime', '>', TIMESTAMP);
  325. $groupbuy = model('groupbuy')->getGroupbuyList($condition);
  326. $update = true;
  327. foreach ($groupbuy as $val) {
  328. $flag = model('goods')->editGoods(array('goods_promotion_price' => $val['groupbuy_price'], 'goods_promotion_type' => 1), array('goods_commonid' => $val['goods_commonid']));
  329. if (!$flag) {
  330. $update = false;
  331. }
  332. }
  333. if (!$update) {
  334. return ds_callback(false);
  335. }
  336. return ds_callback(true);
  337. }
  338. /**
  339. * 抢购过期
  340. *
  341. * @param int $goods_commonid
  342. */
  343. public function editExpireGroupbuy($goods_commonid)
  344. {
  345. $condition = array(array('goods_commonid', '=', $goods_commonid));
  346. //抢购活动过期
  347. $update = model('groupbuy')->editExpireGroupbuy($condition);
  348. if (!$update) {
  349. return ds_callback(false);
  350. }
  351. return ds_callback(true);
  352. }
  353. /**
  354. * 秒杀过期
  355. *
  356. * @param int $xianshi_id
  357. */
  358. public function editExpireXianshi($xianshi_id)
  359. {
  360. $condition = array(array('xianshi_id', '=', $xianshi_id));
  361. //秒杀过期
  362. $update = model('pxianshi')->editExpireXianshi($condition);
  363. if (!$update) {
  364. return ds_callback(false);
  365. }
  366. return ds_callback(true);
  367. }
  368. /**
  369. * 批发过期
  370. *
  371. * @param int $wholesale_id
  372. */
  373. public function editExpireWholesale($wholesale_id)
  374. {
  375. $condition = array(array('wholesale_id', '=', $wholesale_id));
  376. //秒杀过期
  377. $update = model('wholesale')->editExpireWholesale($condition);
  378. if (!$update) {
  379. return ds_callback(false);
  380. }
  381. return ds_callback(true);
  382. }
  383. /**
  384. * 更新使用的平台代金券状态
  385. * @param $input_voucher_list
  386. * @throws Exception
  387. */
  388. public function editMallVoucherState($mallvoucher_info)
  389. {
  390. $mallvoucheruser_model = model('mallvouchertemplate');
  391. $update = $mallvoucheruser_model->editMallVoucherUser(array('mallvoucheruser_state' => $mallvoucher_info['mallvoucheruser_state']), array('mallvoucheruser_id' => $mallvoucher_info['mallvoucheruser_id']), $mallvoucher_info['mallvoucheruser_ownerid']);
  392. return ds_callback(true);
  393. }
  394. }