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