CronController.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class CronController extends \Think\Controller {
  16. /**
  17. 检测退款失败订单
  18. **/
  19. public function check_refund_faild_pintuan()
  20. {
  21. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  22. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  23. RecursiveMkdir($data_path);
  24. set_time_limit(0);
  25. require_once $lib_path."/Weixin/lib/WxPay.Api.php";
  26. require_once $lib_path."/Weixin/log.php";
  27. //初始化日志
  28. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  29. \Log::Init($logHandler, 15);
  30. \Log::DEBUG("检测退款失败订单开始:" );
  31. $weixin_model = D('Home/Weixin');
  32. $refund_orderlist = M('Order')->where( array('order_status_id' => 10, 'total' => array('gt',0)) )->order('pay_time asc')->limit(10)->select();
  33. foreach($refund_orderlist as $order)
  34. {
  35. $input = new \WxPayRefund();
  36. $input->SetTransaction_id($order['transaction_id']);
  37. $res = \WxPayApi::refundQuery($input);
  38. if($res['return_code'] == 'SUCCESS')
  39. {
  40. //查询得到退款记录
  41. $refund_count = $res['refund_count'];
  42. $flag = true;
  43. for($i=0;$i<$refund_count;$i++)
  44. {
  45. if($res['refund_status_'.$i] != 'SUCCESS')
  46. {
  47. $flag = false;
  48. }
  49. }
  50. if($flag)
  51. {
  52. $member_info = M('member')->where( array('member_id' => $order['member_id']) )->find();
  53. //微信后台自动退款成功了。
  54. $weixin_model->refundOrder_success($order,$member_info['openid']);
  55. \Log::DEBUG("订单号:".$order['order_id'].' 微信后台自动退款成功,检测完,更新订单状态并发送消息' );
  56. }else {
  57. var_dump($res);die();
  58. }
  59. }
  60. }
  61. echo 'check weixin auto refund success';
  62. }
  63. public function test()
  64. {
  65. echo 3;
  66. die();
  67. }
  68. /**
  69. 检测订单退款状态是否正常
  70. **/
  71. public function check_pintuan_refundstate()
  72. {
  73. $sql = "SELECT p.pin_id,o.order_id,o.total,o.transaction_id from ".C('DB_PREFIX')."pin as p, ".C('DB_PREFIX')."pin_order as po,
  74. ".C('DB_PREFIX')."order as o where p.pin_id=po.pin_id
  75. and po.order_id = o.order_id and p.state =2 and o.order_status_id=2 limit 30";
  76. $order_list = M()->query($sql);
  77. foreach($order_list as $val)
  78. {
  79. M('pin')->where( array('pin_id' => $val['pin_id']) )->save( array('state' => 0) );
  80. }
  81. //C('DB_PREFIX')
  82. }
  83. /**
  84. * 退款正常商品时钟
  85. */
  86. public function refundPintuan()
  87. {
  88. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  89. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  90. RecursiveMkdir($data_path);
  91. set_time_limit(0);
  92. require_once $lib_path."/Weixin/log.php";
  93. //初始化日志
  94. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  95. \Log::Init($logHandler, 15);
  96. \Log::DEBUG("退款进入:" );
  97. $daytimenow_ev56_s = time();
  98. $condition = " state=0 and end_time < ".$daytimenow_ev56_s;
  99. $pin_list = M('pin')->where( $condition )->order('pin_id asc ')->limit(10)->select();
  100. $weixin_model = D('Home/Weixin');
  101. if(!empty($pin_list)) {
  102. foreach($pin_list as $pin)
  103. {
  104. M('pin')->where(array('pin_id' => $pin['pin_id']))->save( array('state' => 2) );
  105. $pin_order_list = M('pin_order')->where( array('pin_id' =>$pin['pin_id'] ) )->select();
  106. $order_ids = array();
  107. foreach($pin_order_list as $vv)
  108. {
  109. $order_ids[] = $vv['order_id'];
  110. }
  111. $order_list = M('order')->where( array('order_id' => array('in',$order_ids) ,'order_status_id' => 2) )->select();
  112. foreach($order_list as $order)
  113. {
  114. \Log::DEBUG("退款订单ID: ".$order['order_id'] );
  115. $weixin_model->refundOrder($order['order_id']);
  116. //echo 333;die();
  117. }
  118. }
  119. }
  120. \Log::DEBUG("退款完毕:".date('Y-m-d H:i:s') );
  121. $this->auto_opne_lottery();
  122. template_msg_cron();//群发消息
  123. echo '退款成功';
  124. //$order_model = D('Home/Order');
  125. //$order_model->open_goods_lottery_order($goods_id,'',true);
  126. }
  127. /**
  128. 活动过期商品自动下架
  129. **/
  130. public function auto_getdown_activity()
  131. {
  132. $now_time = time();
  133. /**
  134. $subject_goods_list = M('subject_goods')->where("end_time<".$now_time)->select();
  135. foreach($subject_goods_list as $subject_goods)
  136. {
  137. $up_data = array();
  138. $up_data['type'] = 'normal';
  139. $up_data['lock_type'] = 'normal';
  140. //$up_data['status'] = 0;//下架
  141. M('goods')->where( array('goods_id' => $subject_goods['goods_id']) )->save($up_data);
  142. }
  143. M('subject_goods')->where("end_time<".$now_time)->delete();
  144. $spike_goods_list = M('spike_goods')->where("end_time<".$now_time)->select();
  145. foreach($spike_goods_list as $spike_goods)
  146. {
  147. $up_data = array();
  148. $up_data['type'] = 'normal';
  149. $up_data['lock_type'] = 'normal';
  150. //$up_data['status'] = 0;//下架
  151. M('goods')->where( array('goods_id' => $spike_goods['goods_id']) )->save($up_data);
  152. }
  153. M('spike_goods')->where("end_time<".$now_time)->delete();
  154. $super_spike_goods_list = M('super_spike_goods')->where("end_time<".$now_time)->select();
  155. foreach($super_spike_goods_list as $super_spike_goods)
  156. {
  157. $up_data = array();
  158. $up_data['type'] = 'normal';
  159. $up_data['lock_type'] = 'normal';
  160. //$up_data['status'] = 0;//下架
  161. M('goods')->where( array('goods_id' => $super_spike_goods['goods_id']) )->save($up_data);
  162. }
  163. M('super_spike_goods')->where("end_time<".$now_time)->delete();
  164. **/
  165. $expr_day_info = M('config')->field('value')->where( array('name' => 'expr_day') )->find();
  166. $end_time = $now_time;
  167. if(!empty($expr_day_info) && $expr_day_info['value'] > 0)
  168. {
  169. $end_time += 86400 * $expr_day_info['value'];
  170. }else {
  171. $end_time += 86400 * 7;
  172. }
  173. $lottery_goods_list = M('lottery_goods')->where("is_open_lottery = 1 and end_time>=".$end_time)->select();
  174. foreach($lottery_goods_list as $lottery_goods)
  175. {
  176. $goods_info = M('goods')->where( array('goods_id' => $lottery_goods['goods_id'] ) )->find();
  177. if($goods_info['type'] == 'lottery')
  178. {
  179. $up_data = array();
  180. $up_data['type'] = 'normal';
  181. $up_data['lock_type'] = 'normal';
  182. $up_data['status'] = 0;//下架
  183. M('goods')->where( array('goods_id' => $lottery_goods['goods_id']) )->save($up_data);
  184. }
  185. }
  186. M('lottery_goods')->where(" is_open_lottery = 1 and end_time>=".$end_time)->delete();
  187. echo '过期活动商品下架成功';
  188. }
  189. /**
  190. * 自动开奖
  191. */
  192. public function auto_opne_lottery()
  193. {
  194. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  195. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  196. RecursiveMkdir($data_path);
  197. set_time_limit(0);
  198. require_once $lib_path."/Weixin/log.php";
  199. //初始化日志
  200. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  201. \Log::Init($logHandler, 15);
  202. \Log::DEBUG("自动开奖进入:" );
  203. $order_model = D('Home/Order');
  204. $lottery_goods_list = M('lottery_goods')->where("is_open_lottery=0 and is_auto_open = 1 and end_time <".time())->limit(5)->select();
  205. foreach($lottery_goods_list as $lottery_goods)
  206. {
  207. \Log::DEBUG("自动开奖商品id:".$lottery_goods['goods_id'] );
  208. $order_model->open_goods_lottery_order($lottery_goods['goods_id'],'',true);
  209. }
  210. \Log::DEBUG("自动开奖结束:".date('Y-m-d H:i:s') );
  211. echo '自动开奖成功';
  212. }
  213. /**
  214. * 退款抽奖商品时钟
  215. */
  216. public function refundLotteryPintuan()
  217. {
  218. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  219. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  220. RecursiveMkdir($data_path);
  221. set_time_limit(0);
  222. require_once $lib_path."/Weixin/log.php";
  223. //初始化日志
  224. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  225. \Log::Init($logHandler, 15);
  226. \Log::DEBUG("抽奖退款进入:" );
  227. $daytimenow_ev56_s = time();
  228. $condition = " state=1 and is_lottery =1 and lottery_state = 1";
  229. $pin_list = M('pin')->where( $condition )->order('pin_id asc ')->limit(10)->select();
  230. $config_info = M('config')->where( array('name' => 'SITE_URL') )->find();
  231. $weixin_model = D('Home/Weixin');
  232. $voucher_model = D('Home/Voucher');
  233. if(!empty($pin_list)) {
  234. foreach($pin_list as $pin)
  235. {
  236. $sql = "select o.* from ".C('DB_PREFIX')."order as o,".C('DB_PREFIX')."pin_order as p
  237. where o.order_id = p.order_id and o.order_status_id = 1 and p.pin_id = ".$pin['pin_id'];
  238. $order_list = M()->query($sql);
  239. M('pin')->where(array('pin_id' => $pin['pin_id']))->save( array('lottery_state' => 2) );
  240. // return false;
  241. //$order_list = M('order')->where( array('pin_id' =>$pin['pin_id'],'order_status_id' => 1) )->select();
  242. foreach($order_list as $order)
  243. {
  244. if($order['lottery_win'] == 0)
  245. {
  246. //中2等奖
  247. $weixin_model->refundOrder($order['order_id']);
  248. $order_goods = M('order_goods')->where( array('order_id' => $order['order_id']) )->find();
  249. if(!empty($order_goods)) {
  250. $lottery_goods = M('lottery_goods')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  251. if(!empty($lottery_goods) && !empty($lottery_goods['voucher_id'])){
  252. //赠送指定的券
  253. $res = $voucher_model->send_user_voucher_byId($lottery_goods['voucher_id'],$order['member_id']);
  254. if($res == 3)
  255. {
  256. //赠送券成功,发送通知
  257. $member_info = M('member')->where( array('member_id' => $order['member_id']) )->find();
  258. $openId = $member_info['openid'];
  259. $url = $config_info['value'].'/'."/index.php?s=/User/index.html";
  260. $voucher = M('voucher')->where( array('id' => $lottery_goods['voucher_id']) )->find();
  261. $title = "恭喜您中了二等奖,获得{$voucher[credit]}元代金券";
  262. $msg = "亲爱的会员,恭喜您参加 ".$order_goods['name']." 拼团成功,获得{$voucher[credit]}元代金券,立即点击查收哈 ";
  263. \Log::DEBUG("退款送券:".$openId.' '.$msg.' '.$title.' '.$url );
  264. M('order')->where( array('order_id' => $order['order_id']) )->save( array('order_status_id' => 9) );
  265. if( $order['from_type'] == 'wepro' )
  266. {
  267. $template_data = array();
  268. $template_data['keyword1'] = array('value' => $title, 'color' => '#030303');
  269. $template_data['keyword2'] = array('value' => $msg, 'color' => '#030303');
  270. $pay_order_msg_info = M('config')->where( array('name' => 'weprogram_template_lottery_result') )->find();
  271. $template_id = $pay_order_msg_info['value'];
  272. $pagepath = 'pages/dan/quan';
  273. //$order['member_id']
  274. /**
  275. $member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
  276. send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
  277. //更新
  278. M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
  279. $order_info['member_id']
  280. **/
  281. $member_formid_info = M('member_formid')->where( array('member_id' => $order['member_id'],'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
  282. if(!empty($member_formid_info))
  283. {
  284. $rs = send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
  285. M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
  286. }
  287. if( $openId != '1')
  288. {
  289. notify_weixin_msg($openId,$msg,$title,$url);
  290. }
  291. } else {
  292. notify_weixin_msg($openId,$msg,$title,$url);
  293. }
  294. }
  295. }
  296. }
  297. } else if($order['lottery_win'] == 1){
  298. //中了一等奖
  299. $order_goods = M('order_goods')->where( array('order_id' => $order['order_id']) )->find();
  300. \Log::DEBUG("发送一等奖中奖通知:".$openId.' '.$msg.' '.$title.' '.$url );
  301. $member_info = M('member')->where( array('member_id' => $order['member_id']) )->find();
  302. $openId = $member_info['openid'];
  303. $url = $config_info['value'].'/'."/index.php?s=/Order/info/id/".$order['order_id'].".html";
  304. $title = "恭喜您中了一等奖";
  305. $msg = "亲爱的会员,恭喜您参加 ".$order_goods['name']." 拼团成功,您中奖了。请点击查看! ";
  306. if( $order['from_type'] == 'wepro' )
  307. {
  308. $template_data = array();
  309. $template_data['keyword1'] = array('value' => $title, 'color' => '#030303');
  310. $template_data['keyword2'] = array('value' => $msg, 'color' => '#030303');
  311. $pay_order_msg_info = M('config')->where( array('name' => 'weprogram_template_lottery_result') )->find();
  312. $template_id = $pay_order_msg_info['value'];
  313. $pagepath = 'pages/order/order?id='.$order['order_id'];
  314. /**
  315. $order['member_id']
  316. $member_formid_info = M('member_formid')->where( array('member_id' => $order_info['member_id'], 'state' => 0) )->find();
  317. send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
  318. //更新
  319. M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
  320. $order_info['member_id']
  321. **/
  322. $member_formid_info = M('member_formid')->where( array('member_id' => $order['member_id'],'formid' =>array('neq',''), 'state' => 0) )->order('id desc')->find();
  323. if(!empty($member_formid_info))
  324. {
  325. $rs = send_wxtemplate_msg($template_data,$url,$pagepath,$member_info['we_openid'],$template_id,$member_formid_info['formid']);
  326. M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
  327. }
  328. if( $openId != '1')
  329. {
  330. notify_weixin_msg($openId,$msg,$title,$url);
  331. }
  332. } else {
  333. notify_weixin_msg($openId,$msg,$title,$url);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. \Log::DEBUG("抽奖退款完毕:".date('Y-m-d H:i:s') );
  340. echo '抽奖退款成功';
  341. }
  342. /**
  343. * 商家结算
  344. */
  345. public function balanceStore()
  346. {
  347. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  348. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  349. RecursiveMkdir($data_path);
  350. set_time_limit(0);
  351. require_once $lib_path."/Weixin/log.php";
  352. //初始化日志
  353. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  354. \Log::Init($logHandler, 15);
  355. \Log::DEBUG("商家结算进入:".date('Y-m-d H:i:s') );
  356. // $data['balance_time'] = strtotime(date('Y-m-d'));
  357. $has_date_info = M('balance')->where( array('balance_time' => strtotime(date('Y-m-d')) ) )->find();
  358. if($has_date_info) {
  359. \Log::DEBUG("商家已结算强制结束:".date('Y-m-d H:i:s') );
  360. die();
  361. }
  362. $seller_list = M('seller')->where(array('s_status' =>1) )->select();
  363. foreach($seller_list as $seller)
  364. {
  365. $sql = "select o.order_id,o.total,gtc.class_id1,gtc.class_id2,gtc.class_id3 from ".C('DB_PREFIX')."order as o,".C('DB_PREFIX')."order_goods as og,
  366. ".C('DB_PREFIX')."goods_to_category as gtc
  367. where o.order_id = og.order_id and gtc.goods_id = og.goods_id and o.store_id = ".$seller['s_id']."
  368. and o.is_balance = 0 and o.order_status_id in (6,11) ";
  369. $order_list = M()->query($sql);
  370. //获取商家所有绑定类目
  371. $store_bind_class = M('store_bind_class')->where( array('seller_id' => $seller['s_id']) )->select();
  372. $class_rate_arr = array();
  373. foreach($store_bind_class as $bind_class)
  374. {
  375. $key = $bind_class['class_1'].'_'.$bind_class['class_2'].'_'.$bind_class['class_3'];
  376. $class_rate_arr[$key] = $bind_class['commis_rate'];
  377. }
  378. $data = array();
  379. $data['seller_id'] = $seller['s_id'];
  380. $data['money'] = 0;
  381. $data['redusmoney'] = 0;
  382. $data['balance_time'] = strtotime(date('Y-m-d'));
  383. $data['state'] = 2;
  384. $data['addtime'] = time();
  385. $res = M('balance')->add($data);
  386. $bid = M('balance')->getLastInsID();
  387. $tongji_money = 0;
  388. $total_reduce_money = 0;
  389. foreach($order_list as $order)
  390. {
  391. $reduce_money = 0;
  392. $del_moeny = 0;
  393. //$fkey = $order['class_id1'].'_'.$order['class_id2'].'_'.$order['class_id3'];
  394. //只按照一级的类目进行计算
  395. $fkey = $order['class_id1'].'_0_0';
  396. $reduce_money = $order['total'] * $class_rate_arr[$fkey] * 0.01;
  397. $member_commiss_order_list = M('member_commiss_order')->where( array('order_id' =>$order['order_id'],'state' => 0 ) )->select();
  398. if(!empty($member_commiss_order_list))
  399. {
  400. foreach($member_commiss_order_list as $member_commiss_order)
  401. {
  402. //分佣订单
  403. $reduce_money += $member_commiss_order['money'];
  404. M('member_commiss_order')->where( array('id' =>$member_commiss_order['id'] ) )->save( array('state' => 1) );
  405. M('member_commiss')->where( array('member_id' => $member_commiss_order['member_id']) )->setInc('money',$member_commiss_order['money']);
  406. }
  407. }
  408. $del_moeny = $order['total'] - $reduce_money;
  409. $order_data = array();
  410. $order_data['bid'] = $bid;
  411. $order_data['order_id'] = $order['order_id'];
  412. $order_data['seller_id'] = $seller['s_id'];
  413. $order_data['money'] = $del_moeny;
  414. $order_data['redusmoney'] = $reduce_money;
  415. $order_data['addtime'] = time();
  416. M('balance_order')->add($order_data);
  417. M('order')->where( array('order_id' => $order['order_id']))->save( array('is_balance' => 1) );
  418. $order_history = array();
  419. $order_history['order_id'] = $order['order_id'];
  420. $order_history['order_status_id'] = 11;
  421. $order_history['notify'] = 0;
  422. $order_history['comment'] = '订单时钟结算';
  423. $order_history['date_added']=time();
  424. M('order_history')->add($order_history);
  425. $tongji_money += $del_moeny;
  426. $total_reduce_money += $reduce_money;
  427. }
  428. M('balance')->where( array('bid' => $bid) )->save( array('money' => $tongji_money,'redusmoney' => $total_reduce_money) );
  429. $seller_balance = M('seller_balance')->where( array('seller_id' => $seller['s_id']) )->find();
  430. if(empty($seller_balance)) {
  431. $data = array();
  432. $data['money'] = $tongji_money;
  433. $data['seller_id'] = $seller['s_id'];
  434. $data['hasgetmoney'] = 0;
  435. $data['dongmoney'] = 0;
  436. M('seller_balance')->add($data);
  437. } else {
  438. $data = array();
  439. $data['money'] = $tongji_money+ $seller_balance['money'];
  440. M('seller_balance')->where( array('seller_id' => $seller['s_id']) )->save($data);
  441. }
  442. }
  443. \Log::DEBUG("商家结算完毕:".date('Y-m-d H:i:s') );
  444. echo '商家结算完毕';
  445. $this->check_pintuan_refundstate();
  446. }
  447. /**
  448. 申请退款的商品,如果5天,卖家没有处理,那么就退款
  449. **/
  450. public function auto_shenrefund_order()
  451. {
  452. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  453. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  454. RecursiveMkdir($data_path);
  455. set_time_limit(0);
  456. require_once $lib_path."/Weixin/log.php";
  457. //初始化日志
  458. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  459. \Log::Init($logHandler, 15);
  460. \Log::DEBUG("申请退款自动退款进入:".date('Y-m-d H:i:s') );
  461. $default_day = 3;
  462. $config_info = M('config')->where( array('name' => 'autoshenrefundday') )->find();
  463. if(!empty($config_info) && intval($config_info['value']) > 0)
  464. {
  465. $default_day = intval($config_info['value']);
  466. }
  467. $end_time = time() - $default_day * 86400;
  468. $sql = "select o.order_id,orf.ref_money,orf.state from ".C('DB_PREFIX')."order as o,".C('DB_PREFIX')."order_refund as orf
  469. where o.order_id = orf.order_id and orf.state =0 and o.order_status_id in (12) and orf.addtime <".$end_time;
  470. $order_list = M()->query($sql);
  471. foreach($order_list as $order)
  472. {
  473. $order_refund_history = array();
  474. $order_refund_history['order_id'] = $order['order_id'];
  475. $order_refund_history['message'] = '商家未及时处理,自动退款';
  476. $order_refund_history['type'] = 3;
  477. $order_refund_history['addtime'] = time();
  478. M('order_refund_history')->add($order_refund_history);
  479. $order_history = array();
  480. $order_history['order_id'] = $order_id;
  481. $order_history['order_status_id'] = 7;
  482. $order_history['notify'] = 0;
  483. $order_history['comment'] = '商家未及时处理,自动退款';
  484. $order_history['date_added'] = time();
  485. M('order_history')->add($order_history);
  486. $weixin_model = D('Home/Weixin');
  487. //通过
  488. M('order_refund')->where( array('order_id' => $order['order_id']) )->save( array('state' => 3) );
  489. $weixin_model->refundOrder($order['order_id'],$order['ref_money']);
  490. }
  491. \Log::DEBUG("申请退款自动退款完毕:".date('Y-m-d H:i:s') );
  492. echo '申请退款自动退款成功';
  493. }
  494. /**
  495. * 15天自动确认收货
  496. */
  497. public function autoGetPack()
  498. {
  499. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  500. $data_path = dirname( dirname(dirname( dirname(__FILE__) )) ).'/Data/wxpaylogs/'.date('Y-m-d')."/";
  501. RecursiveMkdir($data_path);
  502. set_time_limit(0);
  503. require_once $lib_path."/Weixin/log.php";
  504. //初始化日志
  505. $logHandler= new \CLogFileHandler( $data_path .date('Y-m-d').'.log');
  506. \Log::Init($logHandler, 15);
  507. \Log::DEBUG("自动确认收货进入:".date('Y-m-d H:i:s') );
  508. $default_day = 15;
  509. $config_info = M('config')->where( array('name' => 'autogetday') )->find();
  510. if(!empty($config_info) && intval($config_info['value']) > 0)
  511. {
  512. $default_day = intval($config_info['value']);
  513. }
  514. $ziti_shouhuo = 1;
  515. $ziti_config_info = M('config')->where( array('name' => 'ziti_shouhuo') )->find();
  516. if(!empty($ziti_config_info) )
  517. {
  518. $ziti_shouhuo = intval($ziti_config_info['value']);
  519. }
  520. $end_time = time() - $default_day * 86400;
  521. $condition = "";
  522. $condition = "order_status_id=4 and pay_time <".$end_time;
  523. if($ziti_shouhuo == 0)
  524. {
  525. //自提不自动确认收货
  526. //delivery pickup
  527. $condition .= " and delivery != 'pickup' ";
  528. }
  529. $order_list = M('order')->where($condition)->select();
  530. $oid_arr = array();
  531. foreach($order_list as $order)
  532. {
  533. $oid_arr[] = $order['order_id'];
  534. }
  535. if(!empty($oid_arr)) {
  536. $oid_str = implode(',',$oid_arr);
  537. $res = M('order')->where( array('order_id' => array('in',$oid_str)) )->save( array('order_status_id' => 6) );
  538. $integral_model = D('Seller/Integral');
  539. $fenxiao_model = D('Home/Fenxiao');
  540. $share_model = D('Seller/Fissionsharing');
  541. foreach($oid_arr as $order_id)
  542. {
  543. $order_history = array();
  544. $order_history['order_id'] = $order_id;
  545. $order_history['order_status_id'] = 6;
  546. $order_history['notify'] = 0;
  547. $order_history['comment'] = '自动确认收货,超时系统签';
  548. $order_history['date_added']=time();
  549. M('order_history')->add($order_history);
  550. $integral_model->send_order_score_dr($order_id);
  551. $fenxiao_model->send_order_commiss_money($order_id);
  552. $share_model->send_order_commiss_money_do( $order_id);
  553. }
  554. }
  555. \Log::DEBUG("用户自动收货完毕:".date('Y-m-d H:i:s') );
  556. echo '自动收货成功';
  557. $this->auto_shenrefund_order();
  558. $this->auto_getdown_activity();
  559. $this->check_refund_faild_pintuan();
  560. }
  561. }