Queue.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <?php
  2. namespace app\common\logic;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 逻辑层模型
  15. */
  16. class Queue
  17. {
  18. public function addConsume($member_info){
  19. return ds_callback(true);
  20. }
  21. /**
  22. * 添加会员积分
  23. * @param unknown $member_info
  24. */
  25. public function addPoint($member_info)
  26. {
  27. $points_model = model('points');
  28. $points_model->savePointslog('login', array(
  29. 'pl_memberid' => $member_info['member_id'], 'pl_membername' => $member_info['member_name']
  30. ), true);
  31. return ds_callback(true);
  32. }
  33. /**
  34. * 添加会员经验值
  35. * @param unknown $member_info
  36. */
  37. public function addExppoint($member_info)
  38. {
  39. $exppoints_model = model('exppoints');
  40. $exppoints_model->saveExppointslog('login', array(
  41. 'explog_memberid' => $member_info['member_id'], 'explog_membername' => $member_info['member_name']
  42. ), true);
  43. return ds_callback(true);
  44. }
  45. /**
  46. * 更新抢购信息
  47. * @param unknown $groupbuy_info
  48. * @throws Exception
  49. */
  50. public function editGroupbuySaleCount($groupbuy_info)
  51. {
  52. $groupbuy_model = model('groupbuy');
  53. $data = array();
  54. $data['groupbuy_buyer_count'] = Db::raw('groupbuy_buyer_count+1');
  55. $data['groupbuy_buy_quantity'] = Db::raw('groupbuy_buy_quantity+'.$groupbuy_info['quantity']);
  56. $update = $groupbuy_model->editGroupbuy($data, array('groupbuy_id' => $groupbuy_info['groupbuy_id']));
  57. if (!$update) {
  58. return ds_callback(false, '更新抢购信息失败groupbuy_id:' . $groupbuy_info['groupbuy_id']);
  59. }
  60. else {
  61. return ds_callback(true);
  62. }
  63. }
  64. /**
  65. * 更新使用的代金券状态
  66. * @param $input_voucher_list
  67. * @throws Exception
  68. */
  69. public function editVoucherState($voucher_list)
  70. {
  71. $voucher_model = model('voucher');
  72. $send = new \sendmsg\sendMemberMsg();
  73. foreach ($voucher_list as $store_id => $voucher_info) {
  74. $update = $voucher_model->editVoucher(array('voucher_state' => 2), array('voucher_id' => $voucher_info['voucher_id']), $voucher_info['voucher_owner_id']);
  75. if ($update) {
  76. $voucher_model->editVouchertemplate(array('vouchertemplate_id' => $voucher_info['vouchertemplate_id']),array('vouchertemplate_used'=>Db::raw('vouchertemplate_used+1')));
  77. // 发送用户店铺消息
  78. $send->set('member_id', $voucher_info['voucher_owner_id']);
  79. $send->set('code', 'voucher_use');
  80. $ali_param = array();
  81. $ali_param['voucher_code'] = $voucher_info['voucher_code'];
  82. $ten_param=array($voucher_info['voucher_code']);
  83. $param=$ali_param;
  84. $param['voucher_url'] = HOME_SITE_URL .'/Membervoucher/index';
  85. $weixin_param = array(
  86. 'url' => config('ds_config.h5_site_url').'/member/voucher_list',
  87. 'data'=>array(
  88. "keyword1" => array(
  89. "value" => $voucher_info['voucher_code'],
  90. "color" => "#333"
  91. ),
  92. "keyword2" => array(
  93. "value" => date('Y-m-d H:i'),
  94. "color" => "#333"
  95. )
  96. ),
  97. );
  98. $send->send($param,$weixin_param,$ali_param,$ten_param);
  99. }
  100. else {
  101. return ds_callback(false, '更新代金券状态失败vcode:' . $voucher_info['voucher_code']);
  102. }
  103. }
  104. return ds_callback(true);
  105. }
  106. /**
  107. * 下单变更库存销量
  108. * @param unknown $goods_buy_quantity
  109. */
  110. public function createOrderUpdateStorage($goods_buy_quantity)
  111. {
  112. $goods_model = model('goods');
  113. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  114. $data = array();
  115. $data['goods_storage'] = Db::raw('goods_storage-'.$quantity);
  116. $data['goods_salenum'] = Db::raw('goods_salenum+'.$quantity);
  117. $condition=array();
  118. $condition[]=array('goods_id','=',$goods_id);
  119. $condition[]=array('goods_storage','>',0);
  120. $result = $goods_model->editGoods($data, $condition);
  121. if(!$result){
  122. break;
  123. }
  124. }
  125. if (!$result) {
  126. return ds_callback(false, '变更商品库存与销量失败');
  127. }
  128. else {
  129. return ds_callback(true);
  130. }
  131. }
  132. /**
  133. * 取消订单变更库存销量
  134. * @param unknown $goods_buy_quantity
  135. */
  136. public function cancelOrderUpdateStorage($goods_buy_quantity)
  137. {
  138. $goods_model = model('goods');
  139. foreach ($goods_buy_quantity as $goods_id => $quantity) {
  140. $data = array();
  141. $data['goods_storage'] = Db::raw('goods_storage+'.$quantity);
  142. $data['goods_salenum'] = Db::raw('goods_salenum-'.$quantity);
  143. $result = $goods_model->editGoodsById($data, $goods_id);
  144. if (!$result) {
  145. return ds_callback(false, '变更商品库存与销量失败');
  146. }
  147. }
  148. return ds_callback(true);
  149. }
  150. /**
  151. * 更新F码为使用状态
  152. * @param int $goodsfcode_id
  153. */
  154. public function updateGoodsfcode($goodsfcode_id)
  155. {
  156. $update = model('goodsfcode')->editGoodsfcode(array('goodsfcode_state' => 1), array('goodsfcode_id' => $goodsfcode_id));
  157. if (!$update) {
  158. return ds_callback(false, '更新F码使用状态失败goodsfcode_id:' . $goodsfcode_id);
  159. }
  160. else {
  161. return ds_callback(true);
  162. }
  163. }
  164. /**
  165. * 删除购物车
  166. * @param unknown $cart
  167. */
  168. public function delCart($cart)
  169. {
  170. if (!is_array($cart['cart_ids']) || empty($cart['buyer_id']))
  171. return ds_callback(true);
  172. $condition = array();
  173. $condition[] = array('buyer_id','=',$cart['buyer_id']);
  174. $condition[] = array('cart_id','in',$cart['cart_ids']);
  175. $del = model('cart')->delCart('db', $condition,$cart['buyer_id']);
  176. if (!$del) {
  177. return ds_callback(false, '删除购物车数据失败');
  178. }
  179. else {
  180. return ds_callback(true);
  181. }
  182. }
  183. /**
  184. * 根据商品id更新促销价格
  185. *
  186. * @param int /array $goods_commonid
  187. * @return boolean
  188. */
  189. public function updateGoodsPromotionPriceByGoodsId($goods_id)
  190. {
  191. if(!is_array($goods_id)){
  192. $goods_id=(string)$goods_id;
  193. }
  194. $condition = array();
  195. $condition[] = array('goods_id','in', $goods_id);
  196. $update = model('goods')->editGoodsPromotionPrice($condition);
  197. if (!$update) {
  198. return ds_callback(false, '根据商品ID更新促销价格失败');
  199. }
  200. else {
  201. return ds_callback(true);
  202. }
  203. }
  204. /**
  205. * 根据商品公共id更新促销价格
  206. *
  207. * @param int /array $goods_commonid
  208. * @return boolean
  209. */
  210. public function updateGoodsPromotionPriceByGoodsCommonId($goods_commonid)
  211. {
  212. if(!is_array($goods_commonid)){
  213. $goods_commonid=(string)$goods_commonid;
  214. }
  215. $condition = array();
  216. $condition[] = array('goods_commonid','in', $goods_commonid);
  217. $update = model('goods')->editGoodsPromotionPrice($condition);
  218. if (!$update) {
  219. return ds_callback(false, '根据商品公共id更新促销价格失败');
  220. }
  221. else {
  222. return ds_callback(true);
  223. }
  224. }
  225. /**
  226. * 发送店铺消息
  227. */
  228. public function sendStoremsg($param)
  229. {
  230. $send = new \sendmsg\sendStoremsg();
  231. $send->set('code', $param['code']);
  232. $send->set('store_id', $param['store_id']);
  233. $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());
  234. return ds_callback(true);
  235. }
  236. /**
  237. * 发送会员消息
  238. */
  239. public function sendMemberMsg($param)
  240. {
  241. $send = new \sendmsg\sendMemberMsg();
  242. $send->set('code', $param['code']);
  243. $send->set('member_id', $param['member_id']);
  244. if (!empty($param['number']['mobile']))
  245. $send->set('mobile', $param['number']['mobile']);
  246. if (!empty($param['number']['email']))
  247. $send->set('email', $param['number']['email']);
  248. $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());
  249. return ds_callback(true);
  250. }
  251. /**
  252. * 生成商品F码
  253. */
  254. public function createGoodsfcode($param)
  255. {
  256. $insert = array();
  257. for ($i = 0; $i < $param['goodsfcode_count']; $i++) {
  258. $array = array();
  259. $array['goods_commonid'] = $param['goods_commonid'];
  260. $array['goodsfcode_code'] = strtoupper($param['goodsfcode_prefix']) . mt_rand(100000, 999999);
  261. $insert[$array['goodsfcode_code']] = $array;
  262. }
  263. if (!empty($insert)) {
  264. $insert = array_values($insert);
  265. $insert = model('goodsfcode')->addGoodsfcodeAll($insert);
  266. if (!$insert) {
  267. return ds_callback(false, '生成商品F码失败goods_commonid:' . $param['goods_commonid']);
  268. }
  269. }
  270. return ds_callback(true);
  271. }
  272. /**
  273. * 清理特殊商品促销信息
  274. */
  275. public function clearSpecialGoodsPromotion($param)
  276. {
  277. // 抢购
  278. model('groupbuy')->delGroupbuy(array('goods_commonid' => $param['goods_commonid']));
  279. // 显示折扣
  280. $condition = array();
  281. $condition[] = array('goods_id','in', $param['goodsid_array']);
  282. model('pxianshigoods')->delXianshigoods($condition);
  283. // 优惠套装
  284. $condition = array();
  285. $condition[] = array('goods_id','in', $param['goodsid_array']);
  286. model('pbundling')->delBundlingGoods($condition);
  287. // 更新促销价格
  288. model('goods')->editGoods(array('goods_promotion_price' => Db::raw('goods_price'),'goods_promotion_type' => 0), array('goods_commonid' => $param['goods_commonid']));
  289. return ds_callback(true);
  290. }
  291. /**
  292. * 删除(买/卖家)订单全部数量缓存
  293. * @param array $data 订单信息
  294. * @return boolean
  295. */
  296. public function delOrderCountCache($order_info)
  297. {
  298. if (empty($order_info))
  299. return ds_callback(true);
  300. $order_model = model('order');
  301. if (isset($order_info['order_id'])) {
  302. $order_info = $order_model->getOrderInfo(array('order_id' => $order_info['order_id']), array(), 'buyer_id,store_id');
  303. }
  304. if(isset($order_info['buyer_id'])) {
  305. $order_model->delOrderCountCache('buyer', $order_info['buyer_id']);
  306. }
  307. if (isset($order_info['store_id'])) {
  308. $order_model->delOrderCountCache('store', $order_info['store_id']);
  309. }
  310. return ds_callback(true);
  311. }
  312. /**
  313. * 发送兑换码
  314. * @param unknown $param
  315. * @return boolean
  316. */
  317. public function sendVrCode($param)
  318. {
  319. if (empty($param) && !is_array($param))
  320. return ds_callback(true);
  321. $condition = array();
  322. $condition[] = array('order_id','=',$param['order_id']);
  323. $condition[] = array('buyer_id','=',$param['buyer_id']);
  324. $condition[] = array('vr_state','=',0);
  325. $condition[] = array('refund_lock','=',0);
  326. $code_list = model('vrorder')->getShowVrordercodeList($condition, 'vr_code,vr_indate');
  327. if (empty($code_list))
  328. return ds_callback(true);
  329. $content = '';
  330. foreach ($code_list as $v) {
  331. if ($v['type'] == 1) {
  332. $content .= $v['vr_code'] . ',';
  333. }else if($v['type'] == 2){
  334. $content .= $v['vr_code'].' '.$v['vr_secret'] . ',';
  335. } else if($v['type'] == 3){
  336. $content .= $v['vr_qrcode'] . ',';
  337. } else if($v['type'] == 4){
  338. $content .= $v['vr_barcode'] . ',';
  339. }
  340. }
  341. $tpl_info = model('membermsgtpl')->getMembermsgtplInfo(array('membermt_code' => 'send_vr_code'));
  342. $data = array();
  343. $data['vr_code'] = rtrim($content, ',');
  344. $ten_data=array($data['vr_code']);
  345. $message = ds_replace_text($tpl_info['membermt_short_content'], $data);
  346. $smslog_param=array(
  347. 'ali_template_code'=>$tpl_info['ali_template_code'],
  348. 'ali_template_param'=>$data,
  349. 'ten_template_code'=>$tpl_info['ten_template_code'],
  350. 'ten_template_param'=>$ten_data,
  351. 'message'=>$message,
  352. );
  353. $result = model('smslog')->sendSms($param["buyer_phone"], $smslog_param);
  354. if (!$result) {
  355. return ds_callback(false, '兑换码发送失败order_id:' . $param['order_id']);
  356. }
  357. else {
  358. return ds_callback(true);
  359. }
  360. }
  361. /**
  362. * 添加订单代收表内容
  363. */
  364. public function saveChainOrder($param)
  365. {
  366. if (!is_array($param['order_sn_list']))
  367. return ds_callback(true);
  368. $data = array();
  369. $chain_order_model = model('chain_order');
  370. foreach ($param['order_sn_list'] as $order_id => $v) {
  371. $data['order_id'] = $order_id;
  372. $data['order_sn'] = $v['order_sn'];
  373. $data['chain_order_add_time'] = $v['add_time'];
  374. $data['chain_id'] = $param['chain_id'];
  375. $data['chain_order_type'] = 1;
  376. $data['store_id'] = $v['store_id'];
  377. $insert = $chain_order_model->addChainOrder($data);
  378. if (!$insert) {
  379. return ds_callback(false, '保存代收订单信息失败order_sn:' . $v['order_sn']);
  380. }
  381. }
  382. return ds_callback(true);
  383. }
  384. /**
  385. * 发送提货码短信消息
  386. */
  387. public function sendPickupcode($param)
  388. {
  389. $order_common_info = model('order')->getOrdercommonInfo(array('order_id' => $param['order_id']),'reciver_info');
  390. if($order_common_info){
  391. $order_common_info['reciver_info'] = @unserialize($order_common_info['reciver_info']);
  392. $tpl_info = model('mailtemplates')->getTplInfo(array('mailmt_code' => 'send_pickup_code'));
  393. $data = array();
  394. $data['pickup_code'] = $param['pickup_code'];
  395. $ten_data=array($data['pickup_code']);
  396. $message = ds_replace_text($tpl_info['mailmt_content'], $data);
  397. $smslog_param=array(
  398. 'ali_template_code'=>$tpl_info['ali_template_code'],
  399. 'ali_template_param'=>$data,
  400. 'ten_template_code'=>$tpl_info['ten_template_code'],
  401. 'ten_template_param'=>$ten_data,
  402. 'message'=>$message,
  403. );
  404. $result = model('smslog')->sendSms($order_common_info['reciver_info']['mob_phone'], $smslog_param);
  405. if (!$result) {
  406. return ds_callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
  407. }
  408. else {
  409. return ds_callback(true);
  410. }
  411. }else{
  412. return ds_callback(false, '发送提货码短信消息失败order_id:' . $param['order_id']);
  413. }
  414. }
  415. /**
  416. * 生成卡密代金券
  417. */
  418. public function build_pwdvoucher($t_id)
  419. {
  420. $t_id = intval($t_id);
  421. if ($t_id <= 0) {
  422. return ds_callback(false, '参数错误');
  423. }
  424. $voucher_model = model('voucher');
  425. //查询代金券详情
  426. $where = array();
  427. $where[] = array('vouchertemplate_id','=',$t_id);
  428. $gettype_arr = $voucher_model->getVoucherGettypeArray();
  429. $where[] = array('vouchertemplate_gettype','=',$gettype_arr['pwd']['sign']);
  430. $where[] = array('vouchertemplate_isbuild','=',0);
  431. $where[] = array('vouchertemplate_state','=',1);
  432. $t_info = $voucher_model->getVouchertemplateInfo($where);
  433. $t_total = intval($t_info['vouchertemplate_total']);
  434. if ($t_total <= 0) {
  435. return ds_callback(false, '代金券模板信息错误');
  436. }
  437. while ($t_total > 0) {
  438. $is_succ = false;
  439. $insert_arr = array();
  440. $step = $t_total > 1000 ? 1000 : $t_total;
  441. for ($t = 0; $t < $step; $t++) {
  442. $voucher_code = $voucher_model->getVoucherCode(0);
  443. if (!$voucher_code) {
  444. continue;
  445. }
  446. $voucher_pwd_arr = $voucher_model->createVoucherPwd($t_info['vouchertemplate_id']);
  447. if (!$voucher_pwd_arr) {
  448. continue;
  449. }
  450. $tmp = array();
  451. $tmp['voucher_code'] = $voucher_code;
  452. $tmp['vouchertemplate_id'] = $t_info['vouchertemplate_id'];
  453. $tmp['voucher_title'] = $t_info['vouchertemplate_title'];
  454. $tmp['voucher_desc'] = $t_info['vouchertemplate_desc'];
  455. $tmp['voucher_startdate'] = $t_info['vouchertemplate_startdate'];
  456. $tmp['voucher_enddate'] = $t_info['vouchertemplate_enddate'];
  457. $tmp['voucher_price'] = $t_info['vouchertemplate_price'];
  458. $tmp['voucher_limit'] = $t_info['vouchertemplate_limit'];
  459. $tmp['voucher_store_id'] = $t_info['vouchertemplate_store_id'];
  460. $tmp['voucher_state'] = 1;
  461. $tmp['voucher_activedate'] = TIMESTAMP;
  462. $tmp['voucher_owner_id'] = 0;
  463. $tmp['voucher_owner_name'] = '';
  464. $tmp['voucher_order_id'] = 0;
  465. $tmp['voucher_pwd'] = $voucher_pwd_arr[0];//md5
  466. $tmp['voucher_pwd2'] = $voucher_pwd_arr[1];
  467. $insert_arr[] = $tmp;
  468. $t_total--;
  469. }
  470. $result = $voucher_model->addVoucherBatch($insert_arr);
  471. if ($result && $is_succ == false) {
  472. $is_succ = true;
  473. }
  474. }
  475. //更新代金券模板
  476. if ($is_succ) {
  477. $voucher_model->editVouchertemplate(array('vouchertemplate_id' => $t_info['vouchertemplate_id']), array('vouchertemplate_isbuild' => 1));
  478. return ds_callback(true);
  479. }
  480. else {
  481. return ds_callback(false);
  482. }
  483. }
  484. }