Cron.php 17 KB

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