Cron.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. # 获取7天后完成的订单 准备分账
  7. public function yspay()
  8. {
  9. $time = time();
  10. $where['status'] = '5,6';
  11. $where['cdate'] = $time - 7*86400;
  12. $order = Dever::db('shop/sell_order')->getDataByTime($where);
  13. print_r($order);die;
  14. if ($order) {
  15. }
  16. }
  17. public function setGoodsStatus_api()
  18. {
  19. $goods = Dever::db('goods/info')->select();
  20. if ($goods) {
  21. foreach ($goods as $k => $v) {
  22. Dever::db('shop/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
  23. Dever::db('store/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
  24. Dever::db('factory/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
  25. }
  26. }
  27. }
  28. /**
  29. * 处理优惠券到期时间
  30. *
  31. * @return mixed
  32. */
  33. public function coupon_api()
  34. {
  35. $coupon = Dever::db('shop/user_coupon')->getAll(array('status' => 1, 'edate' => time() - 86400));
  36. if ($coupon && Dever::project('message')) {
  37. foreach ($coupon as $k => $v) {
  38. $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
  39. $msg = $coupon_info['name'] . ",要到期啦!";
  40. $msg_param['type'] = 2;//消息类型2是优惠券
  41. $msg_param['id'] = $v['id'];
  42. $msg_param['coupon_id'] = $v['coupon_id'];
  43. $msg_param = Dever::json_encode($msg_param);
  44. Dever::load('message/lib/data')->push(-1, $v['uid'], '优惠劵到期提醒', $msg, 2, 1, false, $msg_param);
  45. if (Dever::load('wechat_applet') && $v['uid'] && $v['uid'] > 0) {
  46. $user = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'system_id' => 1, 'system_source' => 5));
  47. if ($user && $user['openid']) {
  48. $send = array
  49. (
  50. 'thing1' => array
  51. (
  52. 'value' => $coupon_info['name'],
  53. ),
  54. 'time2' => array
  55. (
  56. 'value' => date('Y-m-d H:i', $v['edate']),
  57. ),
  58. 'thing3' => array
  59. (
  60. 'value' => '您有一张优惠券即将到期,请尽快使用',
  61. ),
  62. );
  63. $send = Dever::json_encode($send);
  64. Dever::load('wechat_applet/subscribe')->sendOne('act_2', 1, $user['openid'], 'pages/my/coupon/coupon', $send, Dever::config('base')->wechat_applet);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. /**
  71. * 处理待支付订单提醒
  72. *
  73. * @return mixed
  74. */
  75. public function order_api()
  76. {
  77. # 获取超过5分钟未支付的订单
  78. $time = time();
  79. $where['status'] = 1;
  80. $where['cdate'] = $time - 300;
  81. $order = Dever::db('shop/sell_order')->getDataByTime($where);
  82. if ($order && Dever::project('message')) {
  83. $config = Dever::db('shop/sell_order')->config;
  84. foreach ($order as $k => $v) {
  85. if ($time - $v['cdate'] >= 900) {
  86. Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'status' => 11, 'notice' => 2));
  87. } elseif ($v['notice'] == 1) {
  88. Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'notice' => 2));
  89. $msg = "您有一笔待付款订单,请及时付款。\r\n订单15分钟内未付款自动取消~";
  90. $shop = Dever::db('shop/info')->one($v['shop_id']);
  91. $msg_param = array();
  92. $msg_param['type'] = 1;//消息类型1是订单消息
  93. $msg_param['id'] = $v['id'];
  94. $msg_param['name'] = $shop['name'];
  95. $msg_param = Dever::json_encode($msg_param);
  96. Dever::load('message/lib/data')->push(-1, $v['uid'], '订单待支付提醒', $msg, 2, 1, false, $msg_param);
  97. if (Dever::load('wechat_applet') && $v['uid'] && $v['uid'] > 0) {
  98. $user = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'system_id' => 1, 'system_source' => 5));
  99. if ($user && $user['openid']) {
  100. $v['status_name'] = $config['status'][$v['status']];
  101. $send = array
  102. (
  103. 'character_string5' => array
  104. (
  105. 'value' => $v['order_num'],
  106. ),
  107. 'amount11' => array
  108. (
  109. 'value' => $v['price'] . '元',
  110. ),
  111. 'phrase13' => array
  112. (
  113. 'value' => $v['status_name'],
  114. ),
  115. 'thing12' => array
  116. (
  117. 'value' => '您有一笔待付款订单,请及时付款。',
  118. ),
  119. );
  120. $send = Dever::json_encode($send);
  121. Dever::load('wechat_applet/subscribe')->sendOne('order_pay', 1, $user['openid'], 'pages/app/order/order?id=' . $v['id'], $send, Dever::config('base')->wechat_applet);
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. /**
  129. * 处理待支付订单提醒
  130. *
  131. * @return mixed
  132. */
  133. public function buy_order_api()
  134. {
  135. $time = time();
  136. $where['status'] = 1;
  137. $where['cdate'] = $time - 7200;
  138. $order = Dever::db('shop/buy_order')->getDataByTime($where);
  139. if ($order) {
  140. foreach ($order as $k => $v) {
  141. Dever::db('shop/buy_order')->update(array('where_id' => $v['id'], 'status' => 11));
  142. }
  143. }
  144. }
  145. /**
  146. * 处理销售数据 生成每天的销量统计
  147. *
  148. * @return mixed
  149. */
  150. public function sell_api()
  151. {
  152. $num = Dever::input('num', 1);
  153. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  154. $end = Dever::input('end', date('Y-m-d'));
  155. $where['status'] = '1,2,3,4,5,6';
  156. $start = Dever::maketime($start . ' 00:00:00');
  157. $end = Dever::maketime($end . ' 23:59:59');
  158. $day = intval(($end - $start)/86400);
  159. $shop = Dever::db('shop/info')->select();
  160. foreach ($shop as $k => $v) {
  161. $where['shop_id'] = $v['id'];
  162. for($i=0; $i<=$day; $i++) {
  163. $where['start'] = $start + 86400*$i;
  164. $where['end'] = $start + 86400*$i + 86399;
  165. $data = array();
  166. $data['shop_id'] = $v['id'];
  167. $data['day'] = $where['start'];
  168. $info = Dever::db('shop/sell_stat')->find($data);
  169. $cash = Dever::db('shop/sell_order')->getCashNum($where);
  170. $data['cash'] = $cash['total'];
  171. $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
  172. $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
  173. $data['goods'] = $goods['total'];
  174. $data['area'] = $v['area'];
  175. $data['province'] = $v['province'];
  176. $data['city'] = $v['city'];
  177. $data['county'] = $v['county'];
  178. $data['town'] = $v['town'];
  179. if (!$info) {
  180. Dever::db('shop/sell_stat')->insert($data);
  181. } else {
  182. $data['where_id'] = $info['id'];
  183. Dever::db('shop/sell_stat')->update($data);
  184. }
  185. }
  186. }
  187. }
  188. public function buy_api()
  189. {
  190. $num = Dever::input('num', 1);
  191. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  192. $end = Dever::input('end', date('Y-m-d'));
  193. $where['status'] = '1,2,3,4,5,6';
  194. $start = Dever::maketime($start . ' 00:00:00');
  195. $end = Dever::maketime($end . ' 23:59:59');
  196. $day = intval(($end - $start)/86400);
  197. $shop = Dever::db('shop/info')->select();
  198. foreach ($shop as $k => $v) {
  199. $where['shop_id'] = $v['id'];
  200. for($i=0; $i<=$day; $i++) {
  201. $where['start'] = $start + 86400*$i;
  202. //$where['end'] = $start + 86400*$i + 86399;
  203. $data = array();
  204. $data['type'] = 1;
  205. $data['type_id'] = $v['id'];
  206. $data['day'] = $where['start'];
  207. $info = Dever::db('shop/buy_stat')->find($data);
  208. $cash = Dever::db('shop/buy_order')->getCashNum($where);
  209. $data['cash'] = $cash['total'];
  210. $cash = Dever::db('shop/buy_order')->getPCashNum($where);
  211. $data['p_cash'] = $cash['total'];
  212. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  213. $goods = Dever::db('shop/buy_order')->getGoodsNum($where);
  214. $data['goods'] = $goods['total'];
  215. $data['area'] = $v['area'];
  216. $data['province'] = $v['province'];
  217. $data['city'] = $v['city'];
  218. $data['county'] = $v['county'];
  219. $data['town'] = $v['town'];
  220. if (!$info) {
  221. Dever::db('shop/buy_stat')->insert($data);
  222. } else {
  223. $data['where_id'] = $info['id'];
  224. Dever::db('shop/buy_stat')->update($data);
  225. }
  226. }
  227. }
  228. }
  229. # 处理月度对账数据 废弃,直接用结算单处理
  230. public function sell_month_api()
  231. {
  232. return;
  233. $num = Dever::input('num', -1);
  234. if ($num > 0) {
  235. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  236. } else {
  237. $month = Dever::input('start', date('Y-m'));
  238. }
  239. $where['status'] = 2;
  240. $start = Dever::maketime($month . '-01 00:00:00');
  241. $end = Dever::maketime($month . '-31 23:59:59');
  242. $shop = Dever::db('shop/info')->select();
  243. foreach ($shop as $k => $v) {
  244. $where['shop_id'] = $v['id'];
  245. $where['start'] = $start;
  246. $where['end'] = $end;
  247. $data = array();
  248. $data['shop_id'] = $v['id'];
  249. $data['month'] = $start;
  250. $info = Dever::db('shop/sell_stat_month')->find($data);
  251. $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
  252. $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
  253. $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
  254. if (!$info) {
  255. Dever::db('shop/sell_stat_month')->insert($data);
  256. } else {
  257. $data['where_id'] = $info['id'];
  258. Dever::db('shop/sell_stat_month')->update($data);
  259. }
  260. }
  261. }
  262. # 处理月度对账数据:门店采购 废弃,直接用结算单处理
  263. public function buy_month_api()
  264. {
  265. return;
  266. $num = Dever::input('num', -1);
  267. if ($num > 0) {
  268. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  269. } else {
  270. $month = Dever::input('start', date('Y-m'));
  271. }
  272. $where['status'] = '5,6';
  273. $start = Dever::maketime($month . '-01 00:00:00');
  274. $end = Dever::maketime($month . '-31 23:59:59');
  275. $shop = Dever::db('shop/info')->select();
  276. foreach ($shop as $k => $v) {
  277. $where['type'] = 1;
  278. $where['type_id'] = $v['id'];
  279. $where['start'] = $start;
  280. $where['end'] = $end;
  281. $data = array();
  282. $data['shop_id'] = $v['id'];
  283. $data['month'] = $start;
  284. $info = Dever::db('shop/buy_stat_month')->find($data);
  285. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  286. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  287. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  288. if (!$info) {
  289. Dever::db('shop/buy_stat_month')->insert($data);
  290. } else {
  291. $data['where_id'] = $info['id'];
  292. Dever::db('shop/buy_stat_month')->update($data);
  293. }
  294. }
  295. }
  296. # 处理月度对账数据:仓库对账 废弃,直接用结算单处理
  297. public function store_month_api()
  298. {
  299. return;
  300. $num = Dever::input('num', -1);
  301. if ($num > 0) {
  302. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  303. } else {
  304. $month = Dever::input('start', date('Y-m'));
  305. }
  306. $where['status'] = '5,6';
  307. $start = Dever::maketime($month . '-01 00:00:00');
  308. $end = Dever::maketime($month . '-31 23:59:59');
  309. $store = Dever::db('store/info')->select();
  310. foreach ($store as $k => $v) {
  311. $where['type'] = 2;
  312. $where['type_id'] = $v['id'];
  313. $where['start'] = $start;
  314. $where['end'] = $end;
  315. $data = array();
  316. $data['store_id'] = $v['id'];
  317. $data['month'] = $start;
  318. $info = Dever::db('shop/store_stat_month')->find($data);
  319. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  320. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  321. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  322. if (!$info) {
  323. Dever::db('shop/store_stat_month')->insert($data);
  324. } else {
  325. $data['where_id'] = $info['id'];
  326. Dever::db('shop/store_stat_month')->update($data);
  327. }
  328. }
  329. }
  330. # 处理月度对账数据:工厂对账 废弃,直接用结算单处理
  331. public function factory_month_api()
  332. {
  333. return;
  334. $num = Dever::input('num', -1);
  335. if ($num > 0) {
  336. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  337. } else {
  338. $month = Dever::input('start', date('Y-m'));
  339. }
  340. $where['status'] = '5,6';
  341. $start = Dever::maketime($month . '-01 00:00:00');
  342. $end = Dever::maketime($month . '-31 23:59:59');
  343. $factory = Dever::db('factory/info')->select();
  344. foreach ($factory as $k => $v) {
  345. $where['source_type'] = 3;
  346. $where['source_id'] = $v['id'];
  347. $where['start'] = $start;
  348. $where['end'] = $end;
  349. $data = array();
  350. $data['factory_id'] = $v['id'];
  351. $data['month'] = $start;
  352. $info = Dever::db('shop/factory_stat_month')->find($data);
  353. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  354. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  355. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  356. if (!$info) {
  357. Dever::db('shop/factory_stat_month')->insert($data);
  358. } else {
  359. $data['where_id'] = $info['id'];
  360. Dever::db('shop/factory_stat_month')->update($data);
  361. }
  362. }
  363. }
  364. }