Cron.php 16 KB

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