Cron.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace Active\Lib;
  3. Use Dever;
  4. Class Cron{
  5. #活动订单定时关闭
  6. public function job_api()
  7. {
  8. $data = Dever::db('active/order')->state(array('status'=>1));
  9. $time = time();
  10. if ($data) {
  11. foreach ($data as $k => $v) {
  12. if ($v['cdate'] && $time-$v['cdate']>900) {
  13. Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>3));
  14. }
  15. $active = Dever::db('active/info')->find($v['active_id']);
  16. if ($time > $active['act_end']) {
  17. Dever::db('active/order')->update(array('where_id'=>$v['id'],'set_status'=>4));
  18. }
  19. }
  20. }
  21. return 'ok';
  22. }
  23. #活动状态
  24. public function status_api()
  25. {
  26. $data = Dever::db('active/info')->state();
  27. $time = time();
  28. if ($data) {
  29. $where = array();
  30. foreach ($data as $k =>$v) {
  31. if ($v['sign_start']) {
  32. $ids = $this->start($v['cdate'],$v['act_start'],$v['act_end'],$v['sign_start'],$v['sign_end']);
  33. } else {
  34. $ids = $this->start($v['cdate'],$v['act_start'],$v['act_end']);
  35. }
  36. $where['where_id'] = $v['id'];
  37. $where['act_status'] = $ids['act_status'];
  38. Dever::db('active/info')->update($where);
  39. }
  40. }
  41. return 'ok';
  42. }
  43. public function code_api()
  44. {
  45. $data = Dever::db('active/code')->state();
  46. if ($data) {
  47. foreach ($data as $k => $v) {
  48. if ($v['active_id']) {
  49. $active = Dever::db('active/info')->find($v['active_id']);
  50. if ($active['sign_start']) {
  51. $ids = $this->start($active['cdate'],$active['act_start'],$active['act_end'],$active['sign_start'],$active['sign_end']);
  52. } else {
  53. $ids = $this->start($active['cdate'],$active['act_start'],$active['act_end']);
  54. }
  55. $where['where_id'] = $v['id'];
  56. $where['act_status'] = $ids['act_status'];
  57. Dever::db('active/code')->update($where);
  58. }
  59. }
  60. return 'ok';
  61. }
  62. }
  63. public function start($cdate, $act_start, $act_end, $sign_start = false, $sign_end = false)
  64. {
  65. $time = time();
  66. if ($sign_start) {
  67. if ($time < $sign_start){
  68. $where['act_status'] = 1;
  69. } elseif ($sign_end) {
  70. if ($time >= $sign_start && $time < $sign_end) {
  71. $where['act_status'] = 2;
  72. } elseif ($time > $sign_end && $time < $act_start) {
  73. $where['act_status'] = 3;
  74. } elseif ($time > $act_start && $time < $act_end) {
  75. $where['act_status'] = 4;
  76. } elseif ($time > $act_end) {
  77. $where['act_status'] = 5;
  78. }
  79. }
  80. } else {
  81. if($time < $cdate) {
  82. $where['act_status'] = 1;
  83. } elseif ($time > $cdate && $time < $act_start) {
  84. $where['act_status'] = 2;
  85. } elseif ($time > $act_start && $time < $act_end) {
  86. $where['act_status'] = 4;
  87. } elseif ($time > $act_end) {
  88. $where['act_status'] = 5;
  89. }
  90. }
  91. return $where;
  92. }
  93. #更新user表
  94. public function user_api()
  95. {
  96. $data = Dever::db('active/order')->state();
  97. foreach ($data as $k => $v) {
  98. if ($v['mid'] && $v['mid'] > 0) {
  99. $member = Dever::load('active/lib/user')->agent($v, 'mid');
  100. if ($member && $member['mobile']) {
  101. $user = Dever::db('active/user')->find(array('mobile'=>$member['mobile'], 'clear' => true));
  102. if (!$user) {
  103. $insert['name'] = $member['name'];
  104. $insert['mobile'] = $member['mobile'];
  105. $insert['idcard'] = $member['idcard'];
  106. $insert['pass'] = $member['password'];
  107. $insert['old_pwd'] = $member['old_pwd'];
  108. $insert['old_salt'] = $member['old_salt'];
  109. $insert['clear'] = true;
  110. $uid = Dever::db('active/user')->insert($insert);
  111. $ids = Dever::db('active/order')->update(array('where_id' => $v['id'], 'uid' => $uid));
  112. } else {
  113. $uid = $user['id'];
  114. $ids = Dever::db('active/order')->update(array('where_id' => $v['id'], 'uid' => $user['id']));
  115. }
  116. if ($v['status'] == 2 && $uid) {
  117. $code = Dever::db('active/code')->find(array('active_id'=> $v['active_id'],'join_uid'=>$uid,'clear'=>true));
  118. if (!$code) {
  119. $w['active_id'] = $v['active_id'];
  120. $w['join_uid'] = $uid;
  121. $w['buy_uid'] = $uid;
  122. $w['order_id'] = $v['id'];
  123. $w['clear'] = true;
  124. $w['write_code'] = $this->getCode();
  125. $code_id = Dever::db('active/code')->insert($w);
  126. if ($code_id) {
  127. $where['where_id'] = $v['id'];
  128. $where['code_num'] = 1;
  129. $where['no_num'] = 0;
  130. $where['clear'] = true;
  131. Dever::db('active/order')->update($where);
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. public function bcode_api()
  140. {
  141. $order_id = Dever::input('order_id');
  142. $status = 2;
  143. $order = Dever::db('active/order')->one(array('id' => $order_id, 'clear' => true));
  144. if ($order && $status == 2) {
  145. $code = Dever::db('active/code')->find(array('join_uid'=>$order['uid'],'active_id'=>$order['active_id']));
  146. if (!$code) {
  147. $active = Dever::db('active/info')->find($order['active_id']);
  148. $insert['join_uid'] = $order['uid'];
  149. $insert['active_id'] = $order['active_id'];
  150. $insert['buy_uid'] = $order['uid'];
  151. $insert['order_id'] = $order['id'];
  152. $insert['write_code'] = $this->getCode();
  153. $insert['act_status'] = $active['act_status'];
  154. $ids = Dever::db('active/code')->insert($insert);
  155. if ($ids) {
  156. $update['code_num'] = 1;
  157. }
  158. }
  159. $update['status'] = 2;
  160. $update['where_id'] = $order['id'];
  161. Dever::db('active/order')->update($update);
  162. }
  163. return 'ok';
  164. }
  165. #活动核销码
  166. public function getCode()
  167. {
  168. $where['write_code'] = Dever::rand(6, 0);
  169. $state = Dever::db('active/code')->one($where);
  170. if (!$state) {
  171. return $where['write_code'];
  172. } else {
  173. return $this->getCode();
  174. }
  175. }
  176. #更改订单状态
  177. public function update_order_api()
  178. {
  179. $data = Dever::db('active/order')->state();
  180. foreach ($data as $k => $v) {
  181. if ($v['num'] == $v['refund_num']) {
  182. $where['where_id'] = $v['id'];
  183. $where['status'] = 6;
  184. }
  185. if ($v['refund_num'] >0 && $v['refund_num'] != $v['num']) {
  186. $where['where_id'] = $v['id'];
  187. $where['status'] = 7;
  188. }
  189. if (isset($where) && $where) {
  190. Dever::db('active/order')->update($where);
  191. }
  192. }
  193. return 'ok';
  194. }
  195. }