Cron.php 28 KB

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