Cron.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. /**
  7. * 处理优惠券到期时间
  8. *
  9. * @return mixed
  10. */
  11. public function coupon_api()
  12. {
  13. $coupon = Dever::db('shop/user_coupon')->getAll(array('status' => 1, 'edate' => time() - 86400));
  14. if ($coupon && Dever::project('message')) {
  15. foreach ($coupon as $k => $v) {
  16. $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
  17. $msg = $coupon_info['name'] . ",要到期啦!";
  18. $msg_param['type'] = 2;//消息类型2是优惠券
  19. $msg_param['id'] = $v['id'];
  20. $msg_param['coupon_id'] = $v['coupon_id'];
  21. $msg_param = Dever::json_encode($msg_param);
  22. Dever::load('message/lib/data')->push(-1, $v['uid'], '优惠劵到期提醒', $msg, 2, 1, false, $msg_param);
  23. }
  24. }
  25. }
  26. /**
  27. * 处理待支付订单提醒
  28. *
  29. * @return mixed
  30. */
  31. public function order_api()
  32. {
  33. # 获取超过5分钟未支付的订单
  34. $time = time();
  35. $where['status'] = 1;
  36. $where['cdate'] = $time + 300;
  37. $order = Dever::db('shop/sell_order')->getDataByTime($where);
  38. if ($order && Dever::project('message')) {
  39. foreach ($order as $k => $v) {
  40. if ($time - $v['cdate'] >= 900) {
  41. Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'status' => 11));
  42. } else {
  43. $msg = "您有一笔待付款订单,请及时付款。\r\n订单15分钟内未付款自动取消~";
  44. $shop = Dever::db('shop/info')->one($v['shop_id']);
  45. $msg_param['type'] = 1;//消息类型1是订单消息
  46. $msg_param['id'] = $v['id'];
  47. $msg_param['name'] = $shop['name'];
  48. $msg_param = Dever::json_encode($msg_param);
  49. Dever::load('message/lib/data')->push(-1, $v['uid'], '订单待支付提醒', $msg, 2, 1, false, $msg_param);
  50. }
  51. }
  52. }
  53. }
  54. /**
  55. * 处理销售数据 生成每天的销量统计
  56. *
  57. * @return mixed
  58. */
  59. public function sell_api()
  60. {
  61. $num = Dever::input('num', 1);
  62. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  63. $end = Dever::input('end', date('Y-m-d'));
  64. $where['status'] = '1,2,3,4,5,6';
  65. $start = Dever::maketime($start . ' 00:00:00');
  66. $end = Dever::maketime($end . ' 23:59:59');
  67. $day = intval(($end - $start)/86400);
  68. $shop = Dever::db('shop/info')->select();
  69. foreach ($shop as $k => $v) {
  70. $where['shop_id'] = $v['id'];
  71. for($i=0; $i<=$day; $i++) {
  72. $where['start'] = $start + 86400*$i;
  73. $where['end'] = $start + 86400*$i + 86399;
  74. $data = array();
  75. $data['shop_id'] = $v['id'];
  76. $data['day'] = $where['start'];
  77. $info = Dever::db('shop/sell_stat')->find($data);
  78. $cash = Dever::db('shop/sell_order')->getCashNum($where);
  79. $data['cash'] = $cash['total'];
  80. $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
  81. $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
  82. $data['goods'] = $goods['total'];
  83. $data['area'] = $v['area'];
  84. $data['province'] = $v['province'];
  85. $data['city'] = $v['city'];
  86. $data['county'] = $v['county'];
  87. $data['town'] = $v['town'];
  88. if (!$info) {
  89. Dever::db('shop/sell_stat')->insert($data);
  90. } else {
  91. $data['where_id'] = $info['id'];
  92. Dever::db('shop/sell_stat')->update($data);
  93. }
  94. }
  95. }
  96. }
  97. public function buy_api()
  98. {
  99. $num = Dever::input('num', 1);
  100. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  101. $end = Dever::input('end', date('Y-m-d'));
  102. $where['status'] = '1,2,3,4,5,6';
  103. $start = Dever::maketime($start . ' 00:00:00');
  104. $end = Dever::maketime($end . ' 23:59:59');
  105. $day = intval(($end - $start)/86400);
  106. $shop = Dever::db('shop/info')->select();
  107. foreach ($shop as $k => $v) {
  108. $where['shop_id'] = $v['id'];
  109. for($i=0; $i<=$day; $i++) {
  110. $where['start'] = $start + 86400*$i;
  111. //$where['end'] = $start + 86400*$i + 86399;
  112. $data = array();
  113. $data['type'] = 1;
  114. $data['type_id'] = $v['id'];
  115. $data['day'] = $where['start'];
  116. $info = Dever::db('shop/buy_stat')->find($data);
  117. $cash = Dever::db('shop/buy_order')->getCashNum($where);
  118. $data['cash'] = $cash['total'];
  119. $cash = Dever::db('shop/buy_order')->getPCashNum($where);
  120. $data['p_cash'] = $cash['total'];
  121. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  122. $goods = Dever::db('shop/buy_order')->getGoodsNum($where);
  123. $data['goods'] = $goods['total'];
  124. $data['area'] = $v['area'];
  125. $data['province'] = $v['province'];
  126. $data['city'] = $v['city'];
  127. $data['county'] = $v['county'];
  128. $data['town'] = $v['town'];
  129. if (!$info) {
  130. Dever::db('shop/buy_stat')->insert($data);
  131. } else {
  132. $data['where_id'] = $info['id'];
  133. Dever::db('shop/buy_stat')->update($data);
  134. }
  135. }
  136. }
  137. }
  138. # 处理月度对账数据 废弃,直接用结算单处理
  139. public function sell_month_api()
  140. {
  141. return;
  142. $num = Dever::input('num', -1);
  143. if ($num > 0) {
  144. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  145. } else {
  146. $month = Dever::input('start', date('Y-m'));
  147. }
  148. $where['status'] = 2;
  149. $start = Dever::maketime($month . '-01 00:00:00');
  150. $end = Dever::maketime($month . '-31 23:59:59');
  151. $shop = Dever::db('shop/info')->select();
  152. foreach ($shop as $k => $v) {
  153. $where['shop_id'] = $v['id'];
  154. $where['start'] = $start;
  155. $where['end'] = $end;
  156. $data = array();
  157. $data['shop_id'] = $v['id'];
  158. $data['month'] = $start;
  159. $info = Dever::db('shop/sell_stat_month')->find($data);
  160. $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
  161. $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
  162. $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
  163. if (!$info) {
  164. Dever::db('shop/sell_stat_month')->insert($data);
  165. } else {
  166. $data['where_id'] = $info['id'];
  167. Dever::db('shop/sell_stat_month')->update($data);
  168. }
  169. }
  170. }
  171. # 处理月度对账数据:门店采购 废弃,直接用结算单处理
  172. public function buy_month_api()
  173. {
  174. return;
  175. $num = Dever::input('num', -1);
  176. if ($num > 0) {
  177. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  178. } else {
  179. $month = Dever::input('start', date('Y-m'));
  180. }
  181. $where['status'] = '5,6';
  182. $start = Dever::maketime($month . '-01 00:00:00');
  183. $end = Dever::maketime($month . '-31 23:59:59');
  184. $shop = Dever::db('shop/info')->select();
  185. foreach ($shop as $k => $v) {
  186. $where['type'] = 1;
  187. $where['type_id'] = $v['id'];
  188. $where['start'] = $start;
  189. $where['end'] = $end;
  190. $data = array();
  191. $data['shop_id'] = $v['id'];
  192. $data['month'] = $start;
  193. $info = Dever::db('shop/buy_stat_month')->find($data);
  194. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  195. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  196. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  197. if (!$info) {
  198. Dever::db('shop/buy_stat_month')->insert($data);
  199. } else {
  200. $data['where_id'] = $info['id'];
  201. Dever::db('shop/buy_stat_month')->update($data);
  202. }
  203. }
  204. }
  205. # 处理月度对账数据:仓库对账 废弃,直接用结算单处理
  206. public function store_month_api()
  207. {
  208. return;
  209. $num = Dever::input('num', -1);
  210. if ($num > 0) {
  211. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  212. } else {
  213. $month = Dever::input('start', date('Y-m'));
  214. }
  215. $where['status'] = '5,6';
  216. $start = Dever::maketime($month . '-01 00:00:00');
  217. $end = Dever::maketime($month . '-31 23:59:59');
  218. $store = Dever::db('store/info')->select();
  219. foreach ($store as $k => $v) {
  220. $where['type'] = 2;
  221. $where['type_id'] = $v['id'];
  222. $where['start'] = $start;
  223. $where['end'] = $end;
  224. $data = array();
  225. $data['store_id'] = $v['id'];
  226. $data['month'] = $start;
  227. $info = Dever::db('shop/store_stat_month')->find($data);
  228. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  229. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  230. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  231. if (!$info) {
  232. Dever::db('shop/store_stat_month')->insert($data);
  233. } else {
  234. $data['where_id'] = $info['id'];
  235. Dever::db('shop/store_stat_month')->update($data);
  236. }
  237. }
  238. }
  239. # 处理月度对账数据:工厂对账 废弃,直接用结算单处理
  240. public function factory_month_api()
  241. {
  242. return;
  243. $num = Dever::input('num', -1);
  244. if ($num > 0) {
  245. $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
  246. } else {
  247. $month = Dever::input('start', date('Y-m'));
  248. }
  249. $where['status'] = '5,6';
  250. $start = Dever::maketime($month . '-01 00:00:00');
  251. $end = Dever::maketime($month . '-31 23:59:59');
  252. $factory = Dever::db('factory/info')->select();
  253. foreach ($factory as $k => $v) {
  254. $where['source_type'] = 3;
  255. $where['source_id'] = $v['id'];
  256. $where['start'] = $start;
  257. $where['end'] = $end;
  258. $data = array();
  259. $data['factory_id'] = $v['id'];
  260. $data['month'] = $start;
  261. $info = Dever::db('shop/factory_stat_month')->find($data);
  262. $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
  263. $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
  264. $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
  265. if (!$info) {
  266. Dever::db('shop/factory_stat_month')->insert($data);
  267. } else {
  268. $data['where_id'] = $info['id'];
  269. Dever::db('shop/factory_stat_month')->update($data);
  270. }
  271. }
  272. }
  273. }