RedisorderModel.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. <?php
  2. namespace Seller\Model;
  3. class RedisorderModel
  4. {
  5. /**
  6. 同步所有商品库存
  7. **/
  8. function sysnc_allgoods_total()
  9. {
  10. $list = M('lionfish_comshop_goods')->field('id')->select();
  11. foreach($list as $val)
  12. {
  13. $this->sysnc_goods_total($val['id']);
  14. }
  15. }
  16. function show_logs($goods_id)
  17. {
  18. $redis = $this->get_redis_object_do();
  19. $key = 'bu_a_goods_total_'.$goods_id;
  20. $data = $redis->lRange($key,0,1000);
  21. $redis_html = "<table><tr><th>序号</th><th>内容</th></tr>";
  22. $i =1;
  23. foreach( $data as $val )
  24. {
  25. $redis_html .= "<tr><td>{$i}</td><td>".$val."</td></tr>";
  26. }
  27. $redis_html .= "</table>";
  28. echo $redis_html;die();
  29. }
  30. public function inc_daycount()
  31. {
  32. if(!class_exists('Redis')){
  33. return 0;
  34. }
  35. $redis = $this->get_redis_object_do();
  36. $day_time = strtotime( date('Y-m-d'.' 00:00:00') );
  37. $inc_key = "a_order_inc_".$day_time;
  38. $redis->incr($inc_key);
  39. $cur_count = $redis->get($inc_key);
  40. return $cur_count;
  41. }
  42. function get_all_goods_member_data()
  43. {
  44. $redis = $this->get_redis_object_do();
  45. $sku_key = "a_user_goods_*_781";
  46. $res = $redis->keys($sku_key);
  47. $need_data = array();
  48. foreach( $res as $val )
  49. {
  50. $data = $redis->lRange($val,0,100);
  51. $tp_key = explode('_',$val);
  52. foreach( $data as $vv )
  53. {
  54. //a_user_goods_4868_781
  55. $need_data[] = array( 'member_id' => $tp_key[3], 'key' => $val, 'buy_count' => 1 );
  56. }
  57. }
  58. $redis_html = "<table><tr><th>序号</th><th>用户名</th><th>会员id</th><th>购买数量</th></tr>";
  59. $i =1;
  60. foreach( $need_data as $val )
  61. {
  62. $mb_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $val['member_id']) )->find();
  63. $redis_html .= "<tr><td>{$i}</td><td>".$mb_info['username']."</td><td>".$val['member_id']."</td><td>1</td></tr>";
  64. $i++;
  65. }
  66. $redis_html .= "</table>";
  67. echo $redis_html;die();
  68. }
  69. function get_redis_object_do()
  70. {
  71. include_once ROOT_PATH .'Modules/Lib/Redis.class.php';
  72. $config = array(
  73. 'host'=> D('Home/Front')->get_config_by_name('redis_host'),
  74. 'port'=> D('Home/Front')->get_config_by_name('redis_port'),
  75. 'auth' => D('Home/Front')->get_config_by_name('redis_auth'),
  76. );
  77. $redis = \Redisgo::getInstance($config, array('db_id'=>1,'timeout' => 60 ));
  78. return $redis;
  79. }
  80. /**
  81. 获取商品规格里面的库存数据
  82. 'goods_id' => $goods_id,'option_item_ids' => $data['sku_str']
  83. **/
  84. function get_goods_sku_quantity($goods_id, $option_item_ids)
  85. {
  86. if(!class_exists('Redis')){
  87. return -1;
  88. }
  89. $redis = $this->get_redis_object_do();
  90. $sku_key = "a_goods_sku_{$goods_id}_".$option_item_ids;
  91. $quantity = $redis->llen($sku_key);
  92. return $quantity;
  93. }
  94. /**
  95. 下单商品是否数量足够
  96. **/
  97. function check_goods_can_buy($goods_id, $sku_str,$buy_quantity)
  98. {
  99. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  100. if($open_redis_server == 1)
  101. {
  102. if(!class_exists('Redis')){
  103. return true;
  104. }
  105. $total_quantity = $this->get_goods_total_quantity($goods_id);
  106. if($total_quantity < $buy_quantity)
  107. {
  108. return false;
  109. }else if( !empty($sku_str) )
  110. {
  111. $sku_quantity = $this->get_goods_sku_quantity($goods_id, $sku_str);
  112. if($sku_quantity < $buy_quantity)
  113. {
  114. return false;
  115. }else{
  116. return true;
  117. }
  118. }else{
  119. return true;
  120. }
  121. }else{
  122. return true;
  123. }
  124. }
  125. /**
  126. 删除占位
  127. $redis_has_add_list[] = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'] );
  128. **/
  129. function cancle_goods_buy_user($list)
  130. {
  131. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  132. if($open_redis_server == 1)
  133. {
  134. $redis = $this->get_redis_object_do();
  135. foreach($list as $val)
  136. {
  137. $member_id = $val['member_id'];
  138. $goods_id = $val['goods_id'];
  139. $sku_str = $val['sku_str'];
  140. if( !empty($val['sku_str']) )
  141. {
  142. $key = "user_goods_{$member_id}_{$goods_id}_{$sku_str}";
  143. }else{
  144. $key = "user_goods_{$member_id}_{$goods_id}";
  145. }
  146. $redis->lRem($key,0,1);
  147. }
  148. }
  149. }
  150. /**
  151. 补回库存
  152. **/
  153. public function bu_goods_quantity($goods_id,$quantity)
  154. {
  155. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  156. if($open_redis_server == 1)
  157. {
  158. if(!class_exists('Redis')){
  159. return -1;
  160. }
  161. $redis = $this->get_redis_object_do();
  162. $dan_goods_key = 'a_goods_total_'.$goods_id;
  163. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  164. $total = $redis->llen($dan_goods_key);
  165. $redis->lpush($log_dan_goods_key,'cur total quantity:____total:'.$total.'___'.date('Y-m-d H:i:s') );
  166. for( $m=0; $m<$quantity; $m++ )
  167. {
  168. $redis->lpush($dan_goods_key,1);
  169. }
  170. //LLEN list1
  171. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  172. $total = $redis->llen($dan_goods_key);
  173. $redis->lpush($log_dan_goods_key,'back quantity:'.$quantity.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  174. }
  175. }
  176. /**
  177. 补回规格库存
  178. **/
  179. public function bu_goods_sku_quantity($goods_id,$quantity, $sku_str)
  180. {
  181. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  182. if($open_redis_server == 1)
  183. {
  184. if(!class_exists('Redis')){
  185. return -1;
  186. }
  187. $redis = $this->get_redis_object_do();
  188. $sku_key = "a_goods_sku_{$goods_id}_".$sku_str;
  189. for( $m=0; $m<$quantity; $m++ )
  190. {
  191. $redis->lpush($sku_key,1);
  192. }
  193. }
  194. }
  195. public function bu_car_has_delquantity($redis_has_add_list)
  196. {
  197. // $redis_has_add_list[] = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'],'quantity' => $good['quantity'] );
  198. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  199. if($open_redis_server == 1)
  200. {
  201. $redis = $this->get_redis_object_do();
  202. if( !empty($redis_has_add_list) )
  203. {
  204. foreach($redis_has_add_list as $list)
  205. {
  206. $member_id = $list['member_id'];
  207. $goods_id = $list['goods_id'];
  208. $sku_str = $list['sku_str'];
  209. $quantity = $list['quantity'];
  210. if( !empty($sku_str) )
  211. {
  212. $sku_key = "a_goods_sku_{$goods_id}_".$sku_str;
  213. $bu_count = 0;
  214. $ck_res = true;
  215. //补回
  216. for( $m=0; $m<$quantity; $m++ )
  217. {
  218. $redis->lpush($sku_key,1);
  219. }
  220. $dan_goods_key = 'a_goods_total_'.$goods_id;
  221. //补回
  222. for( $m=0; $m<$quantity; $m++ )
  223. {
  224. $redis->lpush($dan_goods_key,1);
  225. }
  226. $dan_goods_key = 'a_goods_total_'.$goods_id;
  227. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  228. $total = $redis->llen($dan_goods_key);
  229. $redis->lpush($log_dan_goods_key,'skuparseadd bu:'.$quantity.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  230. }else{
  231. $dan_goods_key = 'a_goods_total_'.$goods_id;
  232. //补回
  233. for( $m=0; $m<$quantity; $m++ )
  234. {
  235. $redis->lpush($dan_goods_key,1);
  236. }
  237. $dan_goods_key = 'a_goods_total_'.$goods_id;
  238. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  239. $total = $redis->llen($dan_goods_key);
  240. $redis->lpush($log_dan_goods_key,'parseadd bu:'.$quantity.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  241. return 0;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. /**
  248. 判断下单减库存的情况下,库存是否足够
  249. return -1 没有开启redis,
  250. return 0 已经没有库存了
  251. return 1 可以下单的
  252. **/
  253. public function add_goods_buy_user($goods_id, $sku_str,$quantity,$member_id)
  254. {
  255. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  256. if($open_redis_server == 1)
  257. {
  258. if(!class_exists('Redis')){
  259. return -1;
  260. }
  261. $total_quantity = $this->get_goods_total_quantity($goods_id);
  262. $redis = $this->get_redis_object_do();
  263. $dan_goods_key = 'a_goods_total_'.$goods_id;
  264. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  265. $total = $redis->llen($dan_goods_key);
  266. $redis->lpush($log_dan_goods_key,'cur total quantity:____total:'.$total.'___'.date('Y-m-d H:i:s') );
  267. if( !empty($sku_str) )
  268. {
  269. $sku_key = "a_goods_sku_{$goods_id}_".$sku_str;
  270. $bu_count = 0;
  271. $ck_res = true;
  272. for( $j=0;$j<$quantity;$j++ )
  273. {
  274. $count= $redis->lpop($sku_key);
  275. $bu_count++;
  276. if(!$count)
  277. {
  278. $ck_res = false;
  279. }
  280. }
  281. if( !$ck_res )
  282. {
  283. //补回
  284. for( $m=0; $m<$bu_count; $m++ )
  285. {
  286. $redis->lpush($sku_key,1);
  287. }
  288. return 0;
  289. }else{
  290. $bu_total_count = 0;
  291. $ck_total_res = true;
  292. $dan_goods_key = 'a_goods_total_'.$goods_id;
  293. for( $j=0;$j<$quantity;$j++ )
  294. {
  295. $count2 = $redis->lpop($dan_goods_key);
  296. if(!$count2)
  297. {
  298. $ck_total_res = false;
  299. }else{
  300. $bu_total_count++;
  301. }
  302. }
  303. if( !$ck_total_res )
  304. {
  305. //补回
  306. for( $m=0; $m<$bu_total_count; $m++ )
  307. {
  308. $redis->lpush($dan_goods_key,1);
  309. }
  310. $dan_goods_key = 'a_goods_total_'.$goods_id;
  311. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  312. $total = $redis->llen($dan_goods_key);
  313. $redis->lpush($log_dan_goods_key,'skuparseadd bu:'.$bu_total_count.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  314. return 0;
  315. }else{
  316. for( $j=0;$j<$quantity;$j++ )
  317. {
  318. $key = "a_user_goods_{$member_id}_{$goods_id}_{$sku_str}";
  319. $redis->rPush($key,1);//占坑
  320. }
  321. $dan_goods_key = 'a_goods_total_'.$goods_id;
  322. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  323. $total = $redis->llen($dan_goods_key);
  324. $redis->lpush($log_dan_goods_key,'add quantity:'.$quantity.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  325. return 1;
  326. }
  327. }
  328. //已经减过库存了
  329. }else{
  330. $bu_total_count = 0;
  331. $ck_total_res = true;
  332. $dan_goods_key = 'a_goods_total_'.$goods_id;
  333. for( $j=0;$j<$quantity;$j++ )
  334. {
  335. $count2 = $redis->lpop($dan_goods_key);
  336. if(!$count2)
  337. {
  338. $ck_total_res = false;
  339. }else{
  340. $bu_total_count++;
  341. }
  342. }
  343. if( !$ck_total_res )
  344. {
  345. //补回
  346. for( $m=0; $m<$bu_total_count; $m++ )
  347. {
  348. $redis->lpush($dan_goods_key,1);
  349. }
  350. $dan_goods_key = 'a_goods_total_'.$goods_id;
  351. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  352. $total = $redis->llen($dan_goods_key);
  353. $redis->lpush($log_dan_goods_key,'parseadd bu:'.$bu_total_count.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  354. return 0;
  355. }else{
  356. for( $j=0;$j<$quantity;$j++ )
  357. {
  358. $key = "a_user_goods_{$member_id}_{$goods_id}";
  359. $redis->rPush($key,1);//占坑
  360. }
  361. $dan_goods_key = 'a_goods_total_'.$goods_id;
  362. $log_dan_goods_key = 'bu_a_goods_total_'.$goods_id;
  363. $total = $redis->llen($dan_goods_key);
  364. $redis->lpush($log_dan_goods_key,'add quantity:'.$quantity.'____total:'.$total.'___'.date('Y-m-d H:i:s') );
  365. return 1;
  366. }
  367. //已经减过库存了
  368. }
  369. //$ret = $redis->rPush('city', 'guangzhou');
  370. //rPush($key,$value) rPush($key,$value)
  371. }else{
  372. return -1;
  373. }
  374. }
  375. /**
  376. 获取单个商品的总数
  377. **/
  378. function get_goods_total_quantity($goods_id)
  379. {
  380. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  381. if($open_redis_server == 1)
  382. {
  383. if(!class_exists('Redis')){
  384. return -1;
  385. }
  386. $redis = $this->get_redis_object_do();;
  387. $dan_goods_key = 'a_goods_total_'.$goods_id;
  388. $quantity = $redis->llen($dan_goods_key);
  389. return $quantity;
  390. }else{
  391. return -1;
  392. }
  393. }
  394. /**
  395. * 有人拼团
  396. */
  397. function add_pintuan_user( $pin_id )
  398. {
  399. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  400. if($open_redis_server == 1)
  401. {
  402. if(!class_exists('Redis')){
  403. return false;
  404. }
  405. $redis_new_redis = D('Home/Front')->get_config_by_name('redis_new_redis');
  406. $redis = $this->get_redis_object_do();;
  407. $dan_goods_key = '_pintuan_count_'.$pin_id;
  408. $count= $redis->lpop($dan_goods_key);
  409. if(!$count)
  410. {
  411. return 0;
  412. }else{
  413. return 1;
  414. }
  415. }else{
  416. return 1;
  417. }
  418. }
  419. /**
  420. * 同步拼团的占位
  421. */
  422. function sysnc_pintuan_total($pin_id, $total)
  423. {
  424. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  425. if($open_redis_server == 1)
  426. {
  427. if(!class_exists('Redis')){
  428. return false;
  429. }
  430. $redis_new_redis = D('Home/Front')->get_config_by_name('redis_new_redis');
  431. $redis = $this->get_redis_object_do();;
  432. $dan_goods_key = '_pintuan_count_'.$pin_id;
  433. for($i=0; $i< $total; $i++)
  434. {
  435. $redis->lpush($dan_goods_key,1);
  436. }
  437. }
  438. }
  439. /**
  440. * @author yj 2020-06-05
  441. * @desc 将待配送的订单放入到redis list 中,并且两个list 主要好做抢占
  442. * @param $id 配送单id
  443. */
  444. function sysnc_localtown_orderquenu( $id )
  445. {
  446. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  447. if($open_redis_server == 1) {
  448. if (!class_exists('Redis')) {
  449. return false;
  450. }
  451. $redis_new_redis = D('Home/Front')->get_config_by_name('redis_new_redis');
  452. $redis = $this->get_redis_object_do();;
  453. }
  454. }
  455. /**
  456. 同步单个商品库存
  457. //结构
  458. //goods_total_1 => 10
  459. //goods_sku_1_99_88 => 8
  460. **/
  461. function sysnc_goods_total($goods_id)
  462. {
  463. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  464. if($open_redis_server == 1)
  465. {
  466. $goods_info = M('lionfish_comshop_goods')->field('total,hasoption')->where( array('id' => $goods_id) )->find();
  467. if( !empty($goods_info) )
  468. {
  469. if(!class_exists('Redis')){
  470. return false;
  471. }
  472. $redis_new_redis = D('Home/Front')->get_config_by_name('redis_new_redis');
  473. if( empty($redis_new_redis) )
  474. D('Seller/Config')->update( array('redis_new_redis' => 1) );
  475. $redis = $this->get_redis_object_do();
  476. $dan_goods_key = 'a_goods_total_'.$goods_id;
  477. $has_total = $redis->llen($dan_goods_key);
  478. if( $has_total > $goods_info['total'] )
  479. {
  480. $del_count = $has_total - $goods_info['total'];
  481. for($i=0; $i< $del_count; $i++)
  482. {
  483. $redis->lpop($dan_goods_key);
  484. }
  485. }else{
  486. $add_count = $goods_info['total'] - $has_total;
  487. for($i=0; $i< $add_count; $i++)
  488. {
  489. $redis->lpush($dan_goods_key,1);
  490. }
  491. }
  492. //$redis->set($dan_goods_key,$goods_info['total']);
  493. if($goods_info['hasoption'] == 1)
  494. {
  495. $option_list = M('lionfish_comshop_goods_option_item_value')->field('option_item_ids,stock')->where( array('goods_id' => $goods_id) )->select();
  496. if( !empty($option_list) )
  497. {
  498. foreach($option_list as $val)
  499. {
  500. $sku_key = "a_goods_sku_{$goods_id}_".$val['option_item_ids'];
  501. $has_op_total = $redis->llen($sku_key);
  502. if( $has_op_total > $val['stock'] )
  503. {
  504. $del_op_count = $has_op_total - $val['stock'];
  505. for($i=0; $i< $del_op_count; $i++)
  506. {
  507. $redis->lpop($sku_key);
  508. }
  509. }else{
  510. $add_op_count = $val['stock'] - $has_op_total;
  511. for($i=0; $i< $add_op_count; $i++)
  512. {
  513. $redis->lpush($sku_key,1);
  514. }
  515. }
  516. //$redis->set($sku_key,$val['stock']);
  517. }
  518. }
  519. }
  520. }
  521. }
  522. }
  523. /**
  524. * 设置弹窗广告redis数据
  525. */
  526. function sysnc_popadv_list(){
  527. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  528. if($open_redis_server == 1)
  529. {
  530. $now = time();
  531. $pop_list = M('lionfish_comshop_pop_adv')->where(" status = 1 ")->select();
  532. foreach($pop_list as $k=>$v){
  533. $adv_list = M('lionfish_comshop_pop_adv_list')->where(array('ad_id'=>$v['id']))->select();
  534. if(!empty($adv_list)) {
  535. foreach($adv_list as $ak=>$av){
  536. if($av['thumb']){
  537. $av['thumb'] = tomedia($av['thumb']);
  538. }
  539. $adv_list[$ak] = $av;
  540. }
  541. }
  542. $pop_list[$k]['adv_list'] = $adv_list;
  543. }
  544. if(!class_exists('Redis')){
  545. return false;
  546. }
  547. $redis = $this->get_redis_object_do();
  548. $pop_key = "pop_adv_list";
  549. $redis->del($pop_key);
  550. $redis->set($pop_key,serialize($pop_list));
  551. }
  552. }
  553. //获取弹窗广告
  554. function get_popadv_list(){
  555. $pop_list = array();
  556. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  557. if($open_redis_server == 1)
  558. {
  559. $redis = $this->get_redis_object_do();
  560. $pop_key = "pop_adv_list";
  561. $pop_list = $redis->get($pop_key);
  562. $pop_list = unserialize($pop_list);
  563. }
  564. return $pop_list;
  565. }
  566. //判断弹窗广告是否还要再出现
  567. /**
  568. * @param $popadvs
  569. * @param $member_id
  570. * @param $pop_page
  571. * @return int is_show: 1、弹窗广告出现,0、弹窗广告不出现
  572. */
  573. function check_pop_advs($popadvs,$member_id,$pop_page){
  574. $now = time();
  575. $redis = $this->get_redis_object_do();
  576. $is_show = 1;
  577. if(!empty($member_id)){
  578. $pop_key = 'popadv_'.$member_id.'_'.$pop_page.'_'.$popadvs['id'];
  579. $pop_key_time = $redis->get($pop_key);
  580. if(!empty($pop_key_time)){
  581. if($popadvs['is_index_show'] == 1){
  582. $show_time = $popadvs['show_hour']*60*60;
  583. if($now-$show_time > $pop_key_time){//超过时间显示
  584. $is_show = 1;
  585. $redis->set($pop_key, $now);
  586. }else{//未超过不显示
  587. $is_show = 0;
  588. }
  589. }else{
  590. $is_show = 0;
  591. }
  592. }else{
  593. $redis->set($pop_key, $now);
  594. }
  595. }else{
  596. if($popadvs['send_person'] != 3){
  597. $is_show = 0;
  598. }else{
  599. $is_show = 1;
  600. }
  601. }
  602. return $is_show;
  603. }
  604. /**
  605. * 将配送员消息存入redis中
  606. * @param $order_id
  607. */
  608. function set_distribution_delivery_message($order_id){
  609. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  610. if($open_redis_server == 1)
  611. {
  612. $redis = $this->get_redis_object_do();
  613. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  614. $store_id = $order_info['store_id'];
  615. $sql = " select a.username as username,b.openid as openid,b.we_openid as we_openid from ".C('DB_PREFIX')."lionfish_comshop_orderdistribution a "
  616. . " left join ".C('DB_PREFIX')."lionfish_comshop_member b on a.member_id = b.member_id "
  617. . " where b.openid <> '' and a.store_id=".$store_id." and a.state=1 ";
  618. $distribution_list = M()->query($sql);
  619. $key = "deliverylist_".$order_id;
  620. foreach($distribution_list as $k=>$v){
  621. $redis->rPush($key,$v['we_openid']);
  622. }
  623. $set_key = "order_delivery_set";
  624. $redis->sAdd($set_key,$key);
  625. }
  626. }
  627. /**
  628. * 给配送员发送消息
  629. * @param $order_id
  630. */
  631. function send_distribution_delivery_message(){
  632. $count = 0;
  633. $send_count = 10;
  634. $no_send_count = 0;
  635. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  636. if($open_redis_server == 1)
  637. {
  638. $redis = $this->get_redis_object_do();
  639. $set_key = "order_delivery_set";
  640. $order_list = $redis->sMembers($set_key);
  641. foreach($order_list as $k=>$v){
  642. $orders = explode("_",$v);
  643. $order_id = $orders[1];
  644. $order_info = D('Seller/Order')->get_order_delivery_detail($order_id);
  645. for($i = 0;$i < $send_count;$i++){
  646. if($redis->lLen($v) > 0 && $count < $send_count){
  647. $we_openid = $redis->rPop($v);
  648. D('Seller/Order')->send_delivery_msg($order_info,$we_openid);
  649. $count++;
  650. if($count >= $send_count){
  651. break;
  652. }
  653. }
  654. }
  655. if($redis->lLen($v) == 0){
  656. $redis->sRem($set_key,$v);
  657. }
  658. if($count >= $send_count){
  659. break;
  660. }
  661. }
  662. $order_list = $redis->sMembers($set_key);
  663. foreach($order_list as $k=>$v){
  664. $order_id = $v;
  665. $no_send_count = $no_send_count + $redis->lLen($v);
  666. }
  667. }
  668. return $no_send_count;
  669. }
  670. function clear_distribution_delivery_redis($order_id){
  671. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  672. if($open_redis_server == 1)
  673. {
  674. $redis = $this->get_redis_object_do();
  675. $key = "deliverylist_".$order_id;
  676. //删除队列
  677. $redis->del($key);
  678. //清除集合数据
  679. $set_key = "order_delivery_set";
  680. $redis->sRem($set_key,$key);
  681. }
  682. }
  683. }
  684. ?>