PresaleGoodsModel.class.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model;
  4. /**
  5. * 优惠券模块
  6. * @author fish
  7. *
  8. */
  9. class PresaleGoodsModel {
  10. /**
  11. * @author yj
  12. * @desc 取预售首页商品
  13. * @param int $limit
  14. */
  15. public function getIndexPresaleGoods($is_index_show_pa =1)
  16. {
  17. $gpc = I('request.');
  18. $head_id = isset($gpc['head_id']) ? $gpc['head_id'] : 0;
  19. if( isset($gpc['communityId']) && $head_id == 0 )
  20. {
  21. $head_id = $gpc['communityId'];
  22. }
  23. $pageNum = isset($gpc['pageNum']) ? $gpc['pageNum'] : 1;
  24. $per_page = isset($gpc['pre_page']) && !empty($gpc['pre_page']) ? $gpc['pre_page'] : 5;
  25. $gid = $gpc['gid'];
  26. $offset = ($pageNum - 1) * $per_page;
  27. $limit = "{$offset},{$per_page}";
  28. if($head_id == 'undefined') $head_id = '';
  29. $is_only_express = $gpc['is_only_express'];
  30. $is_open_only_express = 0;
  31. if($is_only_express==1) {
  32. $is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
  33. }
  34. if($gid == 'undefined' || $gid =='' || $gid =='null' || $gid ==0)
  35. {
  36. $gid = 0;
  37. }
  38. if( !empty($gid) && $gid > 0)
  39. {
  40. $gids = D('Home/GoodsCategory')->get_index_goods_category($gid,'normal','','',1);
  41. $gidArr = array();
  42. $gidArr[] = $gid;
  43. foreach ($gids as $key => $val) {
  44. $gidArr[] = $val['id'];
  45. }
  46. $gid = implode(',', $gidArr);
  47. }
  48. $token = $gpc['token'];
  49. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  50. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  51. {
  52. //echo json_encode( array('code' => 2) );
  53. //die();
  54. }
  55. $member_id = $weprogram_token['member_id'];
  56. $now_time = time();
  57. $where = " g.grounding =1 and g.type ='presale' ";
  58. $is_index_show = isset($gpc['is_index_show']) ? $gpc['is_index_show'] : $is_index_show_pa;
  59. if($is_index_show==1) {
  60. $where .= " and g.is_index_show = 1 ";
  61. }
  62. if($is_open_only_express==1 && $is_only_express==1) {
  63. $where .= " and gc.is_only_express =1 ";
  64. }
  65. $where .= "and gc.begin_time < {$now_time} ";
  66. $community_goods = D('Home/Pingoods')->get_new_community_index_goods($head_id, $gid, 'g.*,gc.begin_time,gc.end_time,gc.big_img,gc.labelname,gc.video,gc.pick_up_type,gc.pick_up_modify,gc.is_take_fullreduction ', $where,$offset,$per_page);
  67. if( !empty($community_goods) )
  68. {
  69. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  70. $full_money = D('Home/Front')->get_config_by_name('full_money');
  71. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  72. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  73. {
  74. $is_open_fullreduction = 0;
  75. }
  76. $list = array();
  77. foreach($community_goods as $val)
  78. {
  79. $tmp_data = array();
  80. $tmp_data['actId'] = $val['id'];
  81. $tmp_data['spuName'] = '【预售】'.$val['goodsname'];
  82. $tmp_data['spuCanBuyNum'] = $val['total'];
  83. $tmp_data['spuDescribe'] = $val['subtitle'];
  84. $tmp_data['end_time'] = $val['end_time'];
  85. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  86. $productprice = $val['productprice'];
  87. $tmp_data['marketPrice'] = explode('.', $productprice);
  88. if( !empty($val['big_img']) )
  89. {
  90. $tmp_data['bigImg'] = tomedia($val['big_img']);
  91. }
  92. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  93. if( !empty($good_image) )
  94. {
  95. $tmp_data['skuImage'] = tomedia($good_image['image']);
  96. }
  97. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'],$member_id);
  98. $price = $price_arr['price'];
  99. $tmp_data['actPrice'] = explode('.', $price);
  100. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  101. if($is_open_fullreduction == 0)
  102. {
  103. $tmp_data['is_take_fullreduction'] = 0;
  104. }else if($is_open_fullreduction == 1){
  105. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  106. }
  107. // 商品角标
  108. $label_id = unserialize($val['labelname']);
  109. if($label_id){
  110. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  111. if($label_info){
  112. if($label_info['type'] == 1){
  113. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  114. } else {
  115. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  116. }
  117. }
  118. $tmp_data['label_info'] = $label_info;
  119. }
  120. $goods_presale = M('lionfish_comshop_goods_presale')->where(['goods_id' => $val['id'] ])->find();
  121. //增加预售时间:
  122. $tmp_data['presale_ding_time_start_int'] = $goods_presale['presale_ding_time_start'];
  123. $tmp_data['presale_ding_time_end_int'] = $goods_presale['presale_ding_time_end'];
  124. $tmp_data['presale_ding_time_start'] = date('m月d日', $goods_presale['presale_ding_time_start']);
  125. $tmp_data['presale_ding_time_end'] = date('m月d日', $goods_presale['presale_ding_time_end']);
  126. //增加预售定金可抵扣多少钱
  127. $tmp_data['presale_type'] = $goods_presale['presale_type']; //0定金,1全款
  128. $tmp_data['presale_ding_money'] = round($goods_presale['presale_ding_money'], 2); //定金
  129. $tmp_data['presale_deduction_money'] = round($goods_presale['presale_deduction_money'],2); //定金 可抵扣多少钱
  130. $list[] = $tmp_data;
  131. }
  132. return ['code' =>0 ,'list' => $list ];
  133. }else{
  134. return ['code' => 1];
  135. }
  136. }
  137. /**
  138. * @author yj
  139. * @desc 获取购物车结算页 预售信息
  140. * @param $goods_id
  141. */
  142. public function getCheckOutPresaleGoodsInfo( $goods_id , $presale_goods_total )
  143. {
  144. $result = [];
  145. $goods_presale_info = M('lionfish_comshop_goods_presale')->where(['goods_id' => $goods_id ])->find();
  146. if( empty($goods_presale_info) )
  147. {
  148. return ['code' => 1, 'message' => '该商品不是预售类型'];
  149. }
  150. //1、预售价格
  151. $result['goods_price'] = $presale_goods_total;
  152. $result['presale_type'] = $goods_presale_info['presale_type'];//预售方式, 0 定金, 1全款
  153. //2、定金抵扣
  154. $deduction_money = 0;
  155. if( $goods_presale_info['presale_type'] == 0 )
  156. {
  157. //定金抵扣
  158. //$deduction_money = $goods_presale_info['presale_deduction_money'] + $goods_presale_info['presale_ding_money'];
  159. if( empty($goods_presale_info['presale_deduction_money']) )
  160. {
  161. $deduction_money = $goods_presale_info['presale_ding_money'];
  162. }else{
  163. $deduction_money = $goods_presale_info['presale_deduction_money'];
  164. }
  165. $result['presale_ding_money'] = round($goods_presale_info['presale_ding_money'],2);//定金金额
  166. }else if( $goods_presale_info['presale_type'] == 1 )
  167. {
  168. //定金全款
  169. $deduction_money = $presale_goods_total;
  170. $result['presale_ding_money'] = round($presale_goods_total,2);//定金金额
  171. }
  172. $result['deduction_money'] = round($deduction_money,2); //定金抵扣金额 = 定金金额 + 定金抵扣金额 / 如果是全款抵扣,这里等于全款金额
  173. //定金支付结束时间 = 尾款支付开始时间
  174. $result['balance_pay_begintime'] = date('m-d H:i', $goods_presale_info['presale_ding_time_end'] );
  175. if( $goods_presale_info['presale_limit_balancepaytime'] == 0 )
  176. {
  177. //0不限尾款支付时间
  178. $result['balance_pay_endtime'] = '不限尾款支付时间';
  179. }else if( $goods_presale_info['presale_limit_balancepaytime'] == 1 )
  180. {
  181. //限制尾款支付时间
  182. $result['balance_pay_endtime'] = $goods_presale_info['presale_ding_time_end'] + 86400 * $goods_presale_info['presale_balance_paytime'] ;
  183. $result['balance_pay_endtime'] = date('m-d H:i', $result['balance_pay_endtime'] );
  184. }
  185. //3、尾款支付时间
  186. $result['presale_limit_balancepaytime'] = $goods_presale_info['presale_limit_balancepaytime']; //0 不限制尾款支付时间, 1限制时间
  187. $result['presale_balance_paytime'] = $goods_presale_info['presale_balance_paytime'];//尾款限制 几天后 支付
  188. //协议说明:
  189. $presale_agreement = D('Home/Front')->get_config_by_name('presale_agreement');
  190. if( !empty($presale_agreement) )
  191. {
  192. $qian=array("\r\n");
  193. $hou=array("<br/>");
  194. $presale_agreement = str_replace($qian,$hou,$presale_agreement );
  195. }
  196. $result['presale_agreement'] = $presale_agreement;//已经将换行替换成了<br/>
  197. //4、预计发货时间
  198. $result['presale_sendorder_type'] = $goods_presale_info['presale_sendorder_type'];//0 固定时间, 1 购买后几天发货
  199. $result['presale_sendorder_datetime'] = date('Y-m-d', $goods_presale_info['presale_sendorder_datetime']);//固定的发货日期
  200. if( $goods_presale_info['presale_sendorder_afterday'] == 0)
  201. {
  202. $result['presale_sendorder_afterday'] = '当';//支付尾款后几天发货
  203. }else{
  204. $result['presale_sendorder_afterday'] = $goods_presale_info['presale_sendorder_afterday'];//支付尾款后几天发货
  205. }
  206. return ['code' => 0 , 'data' => $result ];
  207. }
  208. /**
  209. * @author yj
  210. * @desc 添加订单预售记录表
  211. * @param $order_id
  212. * @return bool
  213. */
  214. public function addOrderPresale( $order_id )
  215. {
  216. $order_goods = M('lionfish_comshop_order_goods')->where(['order_id' => $order_id ])->find();
  217. $goods_id = $order_goods['goods_id'];
  218. $goods_presale = M('lionfish_comshop_goods_presale')->where(['goods_id' => $goods_id ])->find();
  219. //开始分析插入数据
  220. $ins_data = [];
  221. $ins_data['goods_id'] = $goods_id;
  222. $ins_data['order_id'] = $order_id;
  223. $ins_data['addtime'] = time();
  224. $ins_data['state'] = 0;
  225. $ins_data['presale_type'] = $goods_presale['presale_type'];
  226. $ins_data['presale_ding_money'] = $goods_presale['presale_ding_money'] * $order_goods['quantity'];
  227. $ins_data['presale_deduction_money'] = $goods_presale['presale_type'] == 1 ? 0 : $goods_presale['presale_deduction_money']* $order_goods['quantity'];
  228. $ins_data['presale_limit_balancepaytime'] = $goods_presale['presale_limit_balancepaytime'];
  229. //限制尾款支付时间, 0 限制
  230. if( $goods_presale['presale_limit_balancepaytime'] == 1 )
  231. {
  232. $ins_data['presale_balance_beginpaytime'] = $goods_presale['presale_ding_time_end'];
  233. $ins_data['presale_balance_paytime'] = $goods_presale['presale_ding_time_end'] + 86400 * $goods_presale['presale_balance_paytime'];
  234. }else{
  235. $ins_data['presale_balance_paytime'] = 0;
  236. $ins_data['presale_balance_beginpaytime'] = 0;
  237. }
  238. if( $goods_presale['presale_sendorder_type'] == 0)
  239. {
  240. $ins_data['presale_sendorder_datetime'] = $goods_presale['presale_sendorder_datetime'];//固定的发货日期
  241. }else{
  242. $ins_data['presale_sendorder_datetime'] = 0;
  243. }
  244. M('lionfish_comshop_order_presale')->add( $ins_data );
  245. return true;
  246. }
  247. /**
  248. * @author yj
  249. * @desc 回调支付 预售
  250. * @param $order_id
  251. */
  252. public function payBackOrder( $order_id , $transaction_id )
  253. {
  254. //开始事务 M()->startTrans(); M()->commit(); M()->rollback();
  255. //0 判断是否存在这个
  256. M()->startTrans();
  257. $order_presale = M('lionfish_comshop_order_presale')->where(['order_id' => $order_id ])->find();
  258. $order_info = M('lionfish_comshop_order')->where(['order_id' => $order_id ])->find();
  259. if( empty($order_presale) )
  260. {
  261. M()->rollback();
  262. return ['code' => 1, 'message' => 'no presale_order record'];
  263. }
  264. //不是在待支付状态
  265. if( !in_array( $order_presale['state'], [0,1] ) )
  266. {
  267. M()->rollback();
  268. return ['code' => 1, 'message' => '预售订单不可再支付'];
  269. }
  270. $order_relate = M('lionfish_comshop_order_relate')->where(['order_id' => $order_id ])->find();
  271. $order_all_id = $order_relate['order_all_id'];
  272. $goods_presale = M('lionfish_comshop_goods_presale')->where(['goods_id' => $order_presale['goods_id'] ])->find();
  273. if( $order_presale['state'] == 0 )
  274. {
  275. //1、判断是首次支付,还是二次支付
  276. $update_date = [];
  277. $update_date['state'] = 1;
  278. $update_date['transaction_id_first'] = $transaction_id;
  279. $update_date['first_paytime'] = time();
  280. if( $goods_presale['presale_sendorder_type'] == 0 )
  281. {
  282. //固定时间发货
  283. $update_date['presale_sendorder_datetime'] = $goods_presale['presale_sendorder_datetime'];
  284. }
  285. M('lionfish_comshop_order_presale')->where(['id' => $order_presale['id']])->save( $update_date );
  286. //2、更改 总订单+ 订单状态为15 已付定金 注意如果是到店自提逻辑,这里的处理
  287. $o = array();
  288. $o['order_status_id'] = 15;
  289. $o['paytime']=time();
  290. $o['transaction_id'] = $transaction_id;
  291. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id) )->save($o);
  292. //3、如果是全款预售的,那就变更状态
  293. if( $order_presale['presale_type'] == 1 )
  294. {
  295. $update_date = [];
  296. $update_date['state'] = 2;
  297. $update_date['transaction_id_second'] = $transaction_id;
  298. $update_date['second_paytime'] = time();
  299. if( $goods_presale['presale_sendorder_type'] == 1 ){
  300. //购买后几天发货
  301. $update_date['presale_sendorder_datetime'] = time() + 86400 * $goods_presale['presale_sendorder_afterday'];
  302. D('Home/OrderV2')->modifyOrderGoodsHexiaoTime( $order_id ,$order_presale['goods_id'] , $update_date['presale_sendorder_datetime'] );
  303. }
  304. M('lionfish_comshop_order_presale')->where(['id' => $order_presale['id']])->save( $update_date );
  305. $o = array();
  306. $o['order_status_id'] = 1;
  307. if( $order_info['delivery'] == 'hexiao' )
  308. {
  309. $o['order_status_id'] = 4;
  310. }
  311. $o['paytime']=time();
  312. $o['transaction_id'] = $transaction_id;
  313. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id) )->save($o);
  314. $o = array();
  315. $o['order_status_id'] = 1;
  316. if( $order_info['delivery'] == 'hexiao' )
  317. {
  318. $o['order_status_id'] = 4;
  319. }
  320. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save($o);
  321. //4、更改订单状态为 待发货, 注意如果是到店自提逻辑,这里的处理。
  322. //订单自动配送
  323. D('Home/Order')->order_auto_delivery($order_info);
  324. }
  325. }else if( $order_presale['state'] == 1 ){
  326. //2/首次支付处理 二次支付处理
  327. $update_date = [];
  328. $update_date['state'] = 2;
  329. $update_date['transaction_id_second'] = $transaction_id;
  330. $update_date['second_paytime'] = time();
  331. if( $goods_presale['presale_sendorder_type'] == 1 )
  332. {
  333. //购买后几天发货
  334. $update_date['presale_sendorder_datetime'] = time() + 86400 * $goods_presale['presale_sendorder_afterday'];
  335. D('Home/OrderV2')->modifyOrderGoodsHexiaoTime( $order_id ,$order_presale['goods_id'] , $update_date['presale_sendorder_datetime'] );
  336. }
  337. M('lionfish_comshop_order_presale')->where(['id' => $order_presale['id']])->save( $update_date );
  338. $o = array();
  339. $o['order_status_id'] = 1;
  340. if( $order_info['delivery'] == 'hexiao' )
  341. {
  342. $o['order_status_id'] = 4;
  343. }
  344. $o['paytime']=time();
  345. $o['transaction_id'] = $transaction_id;
  346. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id) )->save($o);
  347. $o = array();
  348. if( $order_info['delivery'] == 'hexiao' )
  349. {
  350. $o['order_status_id'] = 4;
  351. }
  352. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save($o);
  353. //2、更改订单状态为 待发货, 注意如果是到店自提逻辑,这里的处理。
  354. //订单自动配送
  355. D('Home/Order')->order_auto_delivery($order_info);
  356. }
  357. M()->commit();
  358. }
  359. /**
  360. * @author yj
  361. * @desc 获取预售订单信息
  362. * @param $order_id
  363. * @return array
  364. */
  365. public function getOrderPresaleInfo( $order_id )
  366. {
  367. $order_presale = M('lionfish_comshop_order_presale')->where(['order_id' => $order_id ])->find();
  368. if( empty($order_presale) )
  369. {
  370. return ['code' => 1, 'message' => 'no presale_order'];
  371. }
  372. /**
  373. * presale_type 0 定金 1全款
  374. * presale_ding_money 支付定金金额
  375. * presale_deduction_money 定金抵扣金额
  376. * presale_limit_balancepaytime 限制尾款支付时间: 0 限制, 1 不限制
  377. * presale_balance_paydate 如果限制尾款支付时间, 该参数表示, 最晚尾款支付时间
  378. * presale_sendorder_date 尾款支付后发货日期
  379. * state 状态: 0未支付定金, 1已支付定金,未支付尾款, 2已支付尾款
  380. * transaction_id_first 定金微信交易号
  381. * transaction_id_second 尾款微信交易号
  382. * first_paytime 定金支付时间
  383. * second_paytime 尾款支付时间
  384. * need_repay 是否需要再支付, 1 需要支付定金, 2需要支付尾款, 0 不需要支付
  385. *
  386. */
  387. $order_presale['adddate'] = date('Y-m-d H:i:s', $order_presale['addtime']);
  388. $order_presale['presale_balance_paydate'] = date('Y-m-d H:i:s', $order_presale['presale_balance_paytime']);
  389. if($order_presale['presale_sendorder_datetime'] == 0)
  390. { $order_presale['presale_sendorder_date'] = '';
  391. $order_goods = M('lionfish_comshop_order_goods')->where(['order_id' => $order_id])->find();
  392. $goods_id = $order_goods['goods_id'];
  393. $goods_presale = M('lionfish_comshop_goods_presale')->where(['goods_id' => $goods_id ])->find();
  394. $order_presale['presale_sendorder_afterday'] = $goods_presale['presale_sendorder_afterday'];
  395. }
  396. else{
  397. $order_presale['presale_sendorder_date'] = date('Y-m-d H:i:s', $order_presale['presale_sendorder_datetime']);
  398. }
  399. //判断是否已取消 begin
  400. $order_presale['is_unpay_ding_cancle'] = 0;
  401. $order_info = M('lionfish_comshop_order')->where( ['order_id' => $order_id ] )->find();
  402. if( $order_info['order_status_id'] == 5 && $order_presale['state'] == 1 )
  403. {
  404. $order_presale['is_unpay_ding_cancle'] = 1;
  405. }
  406. //end
  407. //定金支付结束时间 = 尾款支付开始时间
  408. $order_presale['balance_pay_begintime'] = date('m-d H:i', $order_presale['presale_balance_beginpaytime'] );
  409. if( $order_presale['presale_limit_balancepaytime'] == 0 )
  410. {
  411. //0不限尾款支付时间
  412. $order_presale['balance_pay_endtime'] = '不限尾款支付时间';
  413. }else if( $order_presale['presale_limit_balancepaytime'] == 1 )
  414. {
  415. //限制尾款支付时间
  416. $order_presale['balance_pay_endtime'] = date('m-d H:i', $order_presale['presale_balance_paytime'] );
  417. //$order_presale['balance_pay_endtime'] = date('m-d H:i', $order_presale['balance_pay_endtime'] );
  418. }
  419. $order_presale['need_repay'] = 0;//是否需要重新发起支付
  420. $now_time = time();
  421. //未付款+预售没有结束
  422. if( $order_presale['state'] == 0 )
  423. {
  424. $order_presale['need_repay'] = 1;
  425. }
  426. if( $order_presale['state'] == 1 )
  427. {
  428. if( ($order_presale['presale_limit_balancepaytime'] == 1 && ( $order_presale['presale_balance_beginpaytime'] < $now_time && $order_presale['presale_balance_paytime'] > $now_time ) ) || $order_presale['presale_limit_balancepaytime'] == 0 )
  429. {
  430. $order_presale['need_repay'] = 2;
  431. }
  432. }
  433. //协议说明:
  434. $presale_agreement = D('Home/Front')->get_config_by_name('presale_agreement');
  435. if( !empty($presale_agreement) )
  436. {
  437. $qian=array("\r\n");
  438. $hou=array("<br/>");
  439. $presale_agreement = str_replace($qian,$hou,$presale_agreement );
  440. }
  441. $order_presale['presale_agreement'] = $presale_agreement;//已经将换行替换成了<br/>
  442. //$order_presale['presale_for_ordermoney'] = empty($order_presale['presale_deduction_money']) && $order_presale['presale_deduction_money'] < 0.01 ? $order_presale['presale_ding_money'] : $order_presale['presale_deduction_money'];
  443. if( $order_presale['presale_deduction_money'] >= 0.01)
  444. {
  445. $order_presale['presale_for_ordermoney'] = $order_presale['presale_deduction_money'];
  446. }else{
  447. $order_presale['presale_for_ordermoney'] = $order_presale['presale_ding_money'] ;
  448. }
  449. return ['code' => 0, 'data' => $order_presale ];
  450. }
  451. /**
  452. * @author yj
  453. * @desc 时钟运行通知
  454. */
  455. public function cronPresaleMsg()
  456. {
  457. $now_time = time();
  458. $notify_time = $now_time - 86400;
  459. $sql = "SELECT * FROM ".C('DB_PREFIX')."lionfish_comshop_order_presale where state = 1 and is_notify = 0 and presale_balance_beginpaytime <= {$now_time} order by id asc limit 1000 ";
  460. $presale_list = M()->query($sql);
  461. if( !empty($presale_list) )
  462. {
  463. foreach( $presale_list as $val )
  464. {
  465. $this->sendPresaleOrderMsg( $val['order_id'] );
  466. M('lionfish_comshop_order_presale')->where(['id' => $val['id'] ])->save( ['is_notify' => 1] );
  467. }
  468. }
  469. //回收预售订单过期的
  470. $sql = "SELECT order_id FROM ".C('DB_PREFIX')."lionfish_comshop_order_presale where state = 1 and presale_limit_balancepaytime = 1 and presale_balance_paytime <= {$now_time} ";
  471. $over_presale_list = M()->query($sql);
  472. if( !empty($over_presale_list) )
  473. {
  474. $over_order_ids = [];
  475. foreach( $over_presale_list as $val )
  476. {
  477. $over_order_ids[] = $val['order_id'];
  478. }
  479. D('Home/OrderV2')->canclePresaleOverOrder($over_order_ids);
  480. }
  481. }
  482. /**
  483. * @author yj
  484. * @desc 发送预售订单订阅消息
  485. * @param $order_id
  486. * @return array
  487. */
  488. public function sendPresaleOrderMsg( $order_id )
  489. {
  490. $order_info = M('lionfish_comshop_order')->where(['order_id' => $order_id ])->find();
  491. $member_id = $order_info['member_id'];
  492. $member_info = M('lionfish_comshop_member')->where(['member_id' => $member_id])->find();
  493. $presale_info = $this->getOrderPresaleInfo( $order_id );
  494. if( $presale_info['code'] == 1 )
  495. {
  496. return ['code' => 1, 'message' => '未找到'];
  497. }
  498. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  499. $url = $shop_domain;
  500. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_presale_ordercan_continuepay' );
  501. if($order_info['delivery'] == 'hexiao'){
  502. $pagepath = 'lionfish_comshop/pages/order/order?id='.$order_info['order_id']."&delivery=hexiao";
  503. }else if( $order_info['delivery'] == 'pickup' )
  504. {
  505. $pagepath = 'lionfish_comshop/pages/order/order?id='.$order_info['order_id']."&delivery=pickup";
  506. }
  507. //id=7853&delivery=pickup
  508. else{
  509. $pagepath = 'lionfish_comshop/pages/order/order?id='.$order_info['order_id'];
  510. }
  511. $order_goods_name = D('Home/OrderGoodsV2')->getOrderGoodsName( $order_id );
  512. $mb_subscribe = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'presale_ordercan_continuepay') )->find();
  513. if( !empty($mb_subscribe) )
  514. {
  515. $order_goods_name2 = mb_substr($order_goods_name,0,20,'utf-8');
  516. $order_goods_name2 = mb_substr( $order_goods_name2,0,10,'utf-8');
  517. $template_data = array();
  518. $template_data['character_string2'] = array('value' => $order_info['order_num_alias'] );
  519. $template_data['thing3'] = array('value' => $order_goods_name2 );
  520. $template_data['thing7'] = array('value' => '商品已到货,请尽快支付尾款' );
  521. D('Seller/User')->send_subscript_msg( $template_data,$url,$pagepath,$member_info['we_openid'],$template_id );
  522. M('lionfish_comshop_subscribe')->where( array('id' => $mb_subscribe['id'] ) )->delete();
  523. }
  524. }
  525. }