Cron.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. # 同步退款状态
  7. public function refund_status_api()
  8. {
  9. $order = Dever::db('shop/sell_order')->select();
  10. foreach ($order as $k => $v) {
  11. if ($v['refund_cash'] > 0) {
  12. if ($v['status'] == 6 || $v['status'] == 8) {
  13. $status = 4;
  14. } else {
  15. $status = 3;
  16. }
  17. } elseif ($v['refund_status'] == 2) {
  18. $status = 2;
  19. } else {
  20. $status = 1;
  21. }
  22. Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'refund_status' => $status));
  23. }
  24. $order = Dever::db('shop/buy_order')->select();
  25. foreach ($order as $k => $v) {
  26. if ($v['refund_cash'] > 0) {
  27. if ($v['status'] == 6 || $v['status'] == 8) {
  28. $status = 4;
  29. } else {
  30. $status = 3;
  31. }
  32. } elseif ($v['refund_status'] == 2) {
  33. $status = 2;
  34. } else {
  35. $status = 1;
  36. }
  37. Dever::db('shop/buy_order')->update(array('where_id' => $v['id'], 'refund_status' => $status));
  38. }
  39. }
  40. # 获取7天后完成的订单 准备分账
  41. public function yspay_api()
  42. {
  43. $day = Dever::input('day', 7);
  44. $time = time();
  45. $where['status'] = '5,6';
  46. $where['withdraw'] = 1;
  47. $where['cdate'] = $time - $day*86400;
  48. $order = Dever::db('shop/sell_order')->getDataByTime($where);
  49. if ($order) {
  50. foreach ($order as $k => $v) {
  51. $this->yspayOne($v);
  52. }
  53. }
  54. }
  55. public function yspayOne($v)
  56. {
  57. $shop = Dever::db('shop/info')->find($v['shop_id']);
  58. if ($v['withdraw'] == 1 && $shop && $shop['mid'] && $shop['status'] == 1) {
  59. if ($v['refund_cash']) {
  60. $v['price'] -= $v['refund_cash'];
  61. $v['price'] = round($v['price'], 2);
  62. }
  63. $cash = $v['price'] * 100;//之后还要加上礼品卡的钱
  64. Dever::load('shop/yspay')->action($shop['mid'], $v['order_num'], 2, $cash);
  65. }
  66. }
  67. public function setGoodsStatus_api()
  68. {
  69. $goods = Dever::db('goods/info')->select();
  70. if ($goods) {
  71. foreach ($goods as $k => $v) {
  72. Dever::db('shop/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
  73. Dever::db('store/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
  74. Dever::db('factory/goods')->updates(array('option_goods_id' => $v['id'], 'set_status' => $v['status']));
  75. }
  76. }
  77. }
  78. /**
  79. * 处理优惠券到期时间
  80. *
  81. * @return mixed
  82. */
  83. public function coupon_api()
  84. {
  85. $coupon = Dever::db('shop/user_coupon')->getAll(array('status' => 1, 'edate' => time() - 86400));
  86. if ($coupon && Dever::project('message')) {
  87. foreach ($coupon as $k => $v) {
  88. $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
  89. $msg = $coupon_info['name'] . ",要到期啦!";
  90. $msg_param['type'] = 2;//消息类型2是优惠券
  91. $msg_param['id'] = $v['id'];
  92. $msg_param['coupon_id'] = $v['coupon_id'];
  93. $msg_param = Dever::json_encode($msg_param);
  94. Dever::load('message/lib/data')->push(-1, $v['uid'], '优惠劵到期提醒', $msg, 2, 1, false, $msg_param);
  95. if (Dever::load('wechat_applet') && $v['uid'] && $v['uid'] > 0) {
  96. $user = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'system_id' => 1, 'system_source' => 5));
  97. if ($user && $user['openid']) {
  98. $send = array
  99. (
  100. 'thing1' => array
  101. (
  102. 'value' => $coupon_info['name'],
  103. ),
  104. 'time2' => array
  105. (
  106. 'value' => date('Y-m-d H:i', $v['edate']),
  107. ),
  108. 'thing3' => array
  109. (
  110. 'value' => '您有一张优惠券即将到期,请尽快使用',
  111. ),
  112. );
  113. $send = Dever::json_encode($send);
  114. Dever::load('wechat_applet/subscribe')->sendOne('act_2', 1, $user['openid'], 'pages/my/coupon/coupon', $send, Dever::config('base')->wechat_applet);
  115. }
  116. }
  117. }
  118. }
  119. }
  120. /**
  121. * 处理待支付订单提醒
  122. *
  123. * @return mixed
  124. */
  125. public function order_api()
  126. {
  127. # 获取超过5分钟未支付的订单
  128. $time = time();
  129. $where['status'] = 1;
  130. $where['cdate'] = $time - 300;
  131. $order = Dever::db('shop/sell_order')->getDataByTime($where);
  132. if ($order && Dever::project('message')) {
  133. $config = Dever::db('shop/sell_order')->config;
  134. foreach ($order as $k => $v) {
  135. if ($time - $v['cdate'] >= 900) {
  136. Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'status' => 11, 'notice' => 2));
  137. } elseif ($v['notice'] == 1) {
  138. Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'notice' => 2));
  139. $msg = "您有一笔待付款订单,请及时付款。\r\n订单15分钟内未付款自动取消~";
  140. $shop = Dever::db('shop/info')->one($v['shop_id']);
  141. $msg_param = array();
  142. $msg_param['type'] = 1;//消息类型1是订单消息
  143. $msg_param['id'] = $v['id'];
  144. $msg_param['name'] = $shop['name'];
  145. $msg_param = Dever::json_encode($msg_param);
  146. Dever::load('message/lib/data')->push(-1, $v['uid'], '订单待支付提醒', $msg, 2, 1, false, $msg_param);
  147. if (Dever::load('wechat_applet') && $v['uid'] && $v['uid'] > 0) {
  148. $user = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'system_id' => 1, 'system_source' => 5));
  149. if ($user && $user['openid']) {
  150. $v['status_name'] = $config['status'][$v['status']];
  151. $send = array
  152. (
  153. 'character_string5' => array
  154. (
  155. 'value' => $v['order_num'],
  156. ),
  157. 'amount11' => array
  158. (
  159. 'value' => $v['price'] . '元',
  160. ),
  161. 'phrase13' => array
  162. (
  163. 'value' => $v['status_name'],
  164. ),
  165. 'thing12' => array
  166. (
  167. 'value' => '您有一笔待付款订单,请及时付款。',
  168. ),
  169. );
  170. $send = Dever::json_encode($send);
  171. Dever::load('wechat_applet/subscribe')->sendOne('order_pay', 1, $user['openid'], 'pages/app/order/order?id=' . $v['id'], $send, Dever::config('base')->wechat_applet);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. /**
  179. * 处理待支付订单提醒
  180. *
  181. * @return mixed
  182. */
  183. public function buy_order_api()
  184. {
  185. $time = time();
  186. $where['status'] = 1;
  187. $where['cdate'] = $time - 7200;
  188. $order = Dever::db('shop/buy_order')->getDataByTime($where);
  189. if ($order) {
  190. foreach ($order as $k => $v) {
  191. Dever::db('shop/buy_order')->update(array('where_id' => $v['id'], 'status' => 11));
  192. }
  193. }
  194. }
  195. /**
  196. * 处理销售数据 生成每天的销量统计
  197. *
  198. * @return mixed
  199. */
  200. public function sell_api()
  201. {
  202. $num = Dever::input('num', 1);
  203. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  204. $end = Dever::input('end', date('Y-m-d'));
  205. $where['status'] = '2,3,4,5,6';
  206. $start = Dever::maketime($start . ' 00:00:00');
  207. $end = Dever::maketime($end . ' 23:59:59');
  208. $day = intval(($end - $start)/86400);
  209. $shop = Dever::db('shop/info')->select();
  210. foreach ($shop as $k => $v) {
  211. $where['shop_id'] = $v['id'];
  212. for($i=0; $i<=$day; $i++) {
  213. $where['start'] = $start + 86400*$i;
  214. $where['end'] = $start + 86400*$i + 86399;
  215. $data = array();
  216. $data['shop_id'] = $v['id'];
  217. $data['day'] = $where['start'];
  218. $info = Dever::db('shop/sell_stat')->find($data);
  219. $cash = Dever::db('shop/sell_order')->getCashNum($where);
  220. $data['cash'] = round($cash['total'], 2);
  221. $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
  222. $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
  223. $data['goods'] = $goods['total'];
  224. $data['area'] = $v['area'];
  225. $data['province'] = $v['province'];
  226. $data['city'] = $v['city'];
  227. $data['county'] = $v['county'];
  228. $data['town'] = $v['town'];
  229. if (!$info) {
  230. Dever::db('shop/sell_stat')->insert($data);
  231. } else {
  232. $data['where_id'] = $info['id'];
  233. Dever::db('shop/sell_stat')->update($data);
  234. }
  235. }
  236. }
  237. }
  238. public function buy_api()
  239. {
  240. $num = Dever::input('num', 1);
  241. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  242. $end = Dever::input('end', date('Y-m-d'));
  243. $where['status'] = '2,3,4,5,6';
  244. $start = Dever::maketime($start . ' 00:00:00');
  245. $end = Dever::maketime($end . ' 23:59:59');
  246. $day = intval(($end - $start)/86400);
  247. $shop = Dever::db('shop/info')->select();
  248. foreach ($shop as $k => $v) {
  249. $where['type'] = 1;
  250. $where['type_id'] = $v['id'];
  251. for($i=0; $i<=$day; $i++) {
  252. $where['start'] = $start + 86400*$i;
  253. $where['end'] = $start + 86400*$i + 86399;
  254. $data = array();
  255. $data['shop_id'] = $v['id'];
  256. $data['day'] = $where['start'];
  257. $info = Dever::db('shop/buy_stat')->find($data);
  258. $cash = Dever::db('shop/buy_order')->getCashNum($where);
  259. $data['cash'] = round($cash['total'], 2);
  260. $cash = Dever::db('shop/buy_order')->getPCashNum($where);
  261. $data['p_cash'] = round($cash['total'], 2);
  262. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  263. $goods = Dever::db('shop/buy_order')->getGoodsNum($where);
  264. $data['goods'] = $goods['total'];
  265. $data['area'] = $v['area'];
  266. $data['province'] = $v['province'];
  267. $data['city'] = $v['city'];
  268. $data['county'] = $v['county'];
  269. $data['town'] = $v['town'];
  270. if (!$info) {
  271. Dever::db('shop/buy_stat')->insert($data);
  272. } else {
  273. $data['where_id'] = $info['id'];
  274. Dever::db('shop/buy_stat')->update($data);
  275. }
  276. }
  277. }
  278. }
  279. /**
  280. * 门店数据统计
  281. *
  282. * @return mixed
  283. */
  284. public function shop_api()
  285. {
  286. $num = Dever::input('num', 1);
  287. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  288. $end = Dever::input('end', date('Y-m-d'));
  289. $start = Dever::maketime($start . ' 00:00:00');
  290. $end = Dever::maketime($end . ' 23:59:59');
  291. $day = intval(($end - $start)/86400);
  292. $shop = Dever::db('shop/info')->select();
  293. foreach ($shop as $k => $v) {
  294. $where = array();
  295. $where['status'] = '2,3,4,5,6';
  296. $where['shop_id'] = $v['id'];
  297. for($i=0; $i<=$day; $i++) {
  298. $where['start'] = $start + 86400*$i;
  299. $where['end'] = $start + 86400*$i + 86399;
  300. $data = array();
  301. $data['shop_id'] = $v['id'];
  302. $data['day'] = $where['start'];
  303. $info = Dever::db('shop/shop_stat')->find($data);
  304. $cash = Dever::db('shop/sell_order')->getCashNum($where);
  305. $data['sell_cash'] = round($cash['total'], 2);
  306. $data['sell_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
  307. $where['type'] = 1;
  308. $where['type_id'] = $v['id'];
  309. $cash = Dever::db('shop/buy_order')->getCashNum($where);
  310. $data['buy_cash'] = round($cash['total'], 2);
  311. $data['buy_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
  312. $data['sl_num'] = 0;
  313. $data['area'] = $v['area'];
  314. $data['province'] = $v['province'];
  315. $data['city'] = $v['city'];
  316. $data['county'] = $v['county'];
  317. $data['town'] = $v['town'];
  318. if (!$info) {
  319. Dever::db('shop/shop_stat')->insert($data);
  320. } else {
  321. $data['where_id'] = $info['id'];
  322. Dever::db('shop/shop_stat')->update($data);
  323. }
  324. }
  325. }
  326. }
  327. /**
  328. * 商品数据统计
  329. *
  330. * @return mixed
  331. */
  332. public function goods_api()
  333. {
  334. $num = Dever::input('num', 1);
  335. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  336. $end = Dever::input('end', date('Y-m-d'));
  337. $where['status'] = '1';
  338. $start = Dever::maketime($start . ' 00:00:00');
  339. $end = Dever::maketime($end . ' 23:59:59');
  340. $day = intval(($end - $start)/86400);
  341. $shop = Dever::db('shop/info')->select();
  342. foreach ($shop as $k => $v) {
  343. $where['shop_id'] = $v['id'];
  344. $goods = Dever::db('shop/goods')->select(array('shop_id' => $v['id']));
  345. if ($goods) {
  346. foreach ($goods as $k1 => $v1) {
  347. $where['goods_id'] = $v1['goods_id'];
  348. $goods_info = Dever::db('goods/info')->find($v1['goods_id']);
  349. for($i=0; $i<=$day; $i++) {
  350. $where['start'] = $start + 86400*$i;
  351. $where['end'] = $start + 86400*$i + 86399;
  352. $data = array();
  353. $data['shop_id'] = $v['id'];
  354. $data['goods_id'] = $v1['goods_id'];
  355. $data['day'] = $where['start'];
  356. $info = Dever::db('shop/goods_stat')->find($data);
  357. $cash = Dever::db('shop/sell_order_goods')->getCashNum($where);
  358. $data['cash'] = round($cash['total'], 2);
  359. $data['num'] = Dever::db('shop/sell_order_goods')->getOrderNum($where);
  360. $data['area'] = $v['area'];
  361. $data['category'] = $goods_info['category'];
  362. if (!$info) {
  363. Dever::db('shop/goods_stat')->insert($data);
  364. } else {
  365. $data['where_id'] = $info['id'];
  366. Dever::db('shop/goods_stat')->update($data);
  367. }
  368. }
  369. }
  370. }
  371. }
  372. }
  373. /**
  374. * 门店数据统计
  375. *
  376. * @return mixed
  377. */
  378. public function user_api()
  379. {
  380. $num = Dever::input('num', 1);
  381. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  382. $end = Dever::input('end', date('Y-m-d'));
  383. $start = Dever::maketime($start . ' 00:00:00');
  384. $end = Dever::maketime($end . ' 23:59:59');
  385. $day = intval(($end - $start)/86400);
  386. $shop = Dever::db('shop/info')->select();
  387. foreach ($shop as $k => $v) {
  388. $where = array();
  389. $where['status'] = '2,3,4,5,6';
  390. $where['shop_id'] = $v['id'];
  391. for($i=0; $i<=$day; $i++) {
  392. $where['start'] = $start + 86400*$i;
  393. $where['end'] = $start + 86400*$i + 86399;
  394. $data = array();
  395. $data['shop_id'] = $v['id'];
  396. $data['day'] = $where['start'];
  397. $info = Dever::db('shop/user_stat')->find($data);
  398. $total = Dever::db('shop/sell_order')->getUser($where);
  399. $data['total'] = count($total);
  400. foreach ($total as $k1 => $v1) {
  401. if ($v1['total'] <= 1) {
  402. unset($total[$k1]);
  403. }
  404. }
  405. $data['num'] = count($total);
  406. $data['order_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
  407. $data['area'] = $v['area'];
  408. if (!$info) {
  409. Dever::db('shop/user_stat')->insert($data);
  410. } else {
  411. $data['where_id'] = $info['id'];
  412. Dever::db('shop/user_stat')->update($data);
  413. }
  414. }
  415. }
  416. }
  417. /**
  418. * 用户排名统计
  419. *
  420. * @return mixed
  421. */
  422. public function user_rank_api()
  423. {
  424. $num = Dever::input('num', 1);
  425. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  426. $end = Dever::input('end', date('Y-m-d'));
  427. $start = Dever::maketime($start . ' 00:00:00');
  428. $end = Dever::maketime($end . ' 23:59:59');
  429. $day = intval(($end - $start)/86400);
  430. $w['start'] = $start;
  431. $w['end'] = $end;
  432. $data = Dever::db('shop/sell_order')->getAllByDate($w);
  433. print_r($data);die;
  434. if ($data) {
  435. foreach ($data as $k => $v) {
  436. }
  437. }
  438. $shop = Dever::db('shop/info')->select();
  439. foreach ($shop as $k => $v) {
  440. $where = array();
  441. $where['status'] = '2,3,4,5,6';
  442. $where['shop_id'] = $v['id'];
  443. for($i=0; $i<=$day; $i++) {
  444. $where['start'] = $start + 86400*$i;
  445. $where['end'] = $start + 86400*$i + 86399;
  446. $data = array();
  447. $data['shop_id'] = $v['id'];
  448. $data['day'] = $where['start'];
  449. $info = Dever::db('shop/shop_stat')->find($data);
  450. $cash = Dever::db('shop/sell_order')->getCashNum($where);
  451. $data['sell_cash'] = round($cash['total'], 2);
  452. $data['sell_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
  453. $where['type'] = 1;
  454. $where['type_id'] = $v['id'];
  455. $cash = Dever::db('shop/buy_order')->getCashNum($where);
  456. $data['buy_cash'] = round($cash['total'], 2);
  457. $data['buy_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
  458. $data['sl_num'] = 0;
  459. $data['area'] = $v['area'];
  460. $data['province'] = $v['province'];
  461. $data['city'] = $v['city'];
  462. $data['county'] = $v['county'];
  463. $data['town'] = $v['town'];
  464. if (!$info) {
  465. Dever::db('shop/shop_stat')->insert($data);
  466. } else {
  467. $data['where_id'] = $info['id'];
  468. Dever::db('shop/shop_stat')->update($data);
  469. }
  470. }
  471. }
  472. }
  473. # 获取下单用户量
  474. public function order_user($where)
  475. {
  476. $where['status'] = '1,2,3,4,5,6';
  477. $user = Dever::db('shop/sell_order')->getUser($where);
  478. return $user;
  479. }
  480. # 处理月度对账数据 废弃,直接用结算单处理
  481. public function sell_month_api()
  482. {
  483. return;
  484. $num = Dever::input('num', -1);
  485. if ($num > 0) {
  486. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  487. } else {
  488. $month = Dever::input('start', date('Y-m'));
  489. }
  490. $where['status'] = 2;
  491. $start = Dever::maketime($month . '-01 00:00:00');
  492. $end = Dever::maketime($month . '-31 23:59:59');
  493. $shop = Dever::db('shop/info')->select();
  494. foreach ($shop as $k => $v) {
  495. $where['shop_id'] = $v['id'];
  496. $where['start'] = $start;
  497. $where['end'] = $end;
  498. $data = array();
  499. $data['shop_id'] = $v['id'];
  500. $data['month'] = $start;
  501. $info = Dever::db('shop/sell_stat_month')->find($data);
  502. $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
  503. $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
  504. $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
  505. if (!$info) {
  506. Dever::db('shop/sell_stat_month')->insert($data);
  507. } else {
  508. $data['where_id'] = $info['id'];
  509. Dever::db('shop/sell_stat_month')->update($data);
  510. }
  511. }
  512. }
  513. # 处理月度对账数据:门店采购 废弃,直接用结算单处理
  514. public function buy_month_api()
  515. {
  516. return;
  517. $num = Dever::input('num', -1);
  518. if ($num > 0) {
  519. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  520. } else {
  521. $month = Dever::input('start', date('Y-m'));
  522. }
  523. $where['status'] = '5,6';
  524. $start = Dever::maketime($month . '-01 00:00:00');
  525. $end = Dever::maketime($month . '-31 23:59:59');
  526. $shop = Dever::db('shop/info')->select();
  527. foreach ($shop as $k => $v) {
  528. $where['type'] = 1;
  529. $where['type_id'] = $v['id'];
  530. $where['start'] = $start;
  531. $where['end'] = $end;
  532. $data = array();
  533. $data['shop_id'] = $v['id'];
  534. $data['month'] = $start;
  535. $info = Dever::db('shop/buy_stat_month')->find($data);
  536. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  537. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  538. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  539. if (!$info) {
  540. Dever::db('shop/buy_stat_month')->insert($data);
  541. } else {
  542. $data['where_id'] = $info['id'];
  543. Dever::db('shop/buy_stat_month')->update($data);
  544. }
  545. }
  546. }
  547. # 处理月度对账数据:仓库对账 废弃,直接用结算单处理
  548. public function store_month_api()
  549. {
  550. return;
  551. $num = Dever::input('num', -1);
  552. if ($num > 0) {
  553. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  554. } else {
  555. $month = Dever::input('start', date('Y-m'));
  556. }
  557. $where['status'] = '5,6';
  558. $start = Dever::maketime($month . '-01 00:00:00');
  559. $end = Dever::maketime($month . '-31 23:59:59');
  560. $store = Dever::db('store/info')->select();
  561. foreach ($store as $k => $v) {
  562. $where['type'] = 2;
  563. $where['type_id'] = $v['id'];
  564. $where['start'] = $start;
  565. $where['end'] = $end;
  566. $data = array();
  567. $data['store_id'] = $v['id'];
  568. $data['month'] = $start;
  569. $info = Dever::db('shop/store_stat_month')->find($data);
  570. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  571. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  572. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  573. if (!$info) {
  574. Dever::db('shop/store_stat_month')->insert($data);
  575. } else {
  576. $data['where_id'] = $info['id'];
  577. Dever::db('shop/store_stat_month')->update($data);
  578. }
  579. }
  580. }
  581. # 处理月度对账数据:工厂对账 废弃,直接用结算单处理
  582. public function factory_month_api()
  583. {
  584. return;
  585. $num = Dever::input('num', -1);
  586. if ($num > 0) {
  587. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  588. } else {
  589. $month = Dever::input('start', date('Y-m'));
  590. }
  591. $where['status'] = '5,6';
  592. $start = Dever::maketime($month . '-01 00:00:00');
  593. $end = Dever::maketime($month . '-31 23:59:59');
  594. $factory = Dever::db('factory/info')->select();
  595. foreach ($factory as $k => $v) {
  596. $where['source_type'] = 3;
  597. $where['source_id'] = $v['id'];
  598. $where['start'] = $start;
  599. $where['end'] = $end;
  600. $data = array();
  601. $data['factory_id'] = $v['id'];
  602. $data['month'] = $start;
  603. $info = Dever::db('shop/factory_stat_month')->find($data);
  604. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  605. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  606. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  607. if (!$info) {
  608. Dever::db('shop/factory_stat_month')->insert($data);
  609. } else {
  610. $data['where_id'] = $info['id'];
  611. Dever::db('shop/factory_stat_month')->update($data);
  612. }
  613. }
  614. }
  615. }