TestOrder.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php declare(strict_types=1);
  2. use PHPUnit\Framework\TestCase;
  3. /**
  4. * Created by PhpStorm.
  5. * User: stanley-king
  6. * Date: 2017/1/13
  7. * Time: 下午11:46
  8. */
  9. define('APP_ID','test');
  10. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  11. require_once(BASE_ROOT_PATH . '/global.php');
  12. require_once(BASE_CORE_PATH . '/lrlz.php');
  13. require_once (BASE_ROOT_PATH . '/fooder.php');
  14. require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
  15. require_once (BASE_ROOT_PATH . '/helper/order_helper.php');
  16. class TestOrder extends TestCase
  17. {
  18. public static function setUpBeforeClass() : void
  19. {
  20. Base::run_util();
  21. }
  22. public static function tearDownAfterClass() : void
  23. {
  24. }
  25. public function testCancelOms()
  26. {
  27. $oms = Logic('delivery');
  28. $oms->cancel_order('9000000002963603');
  29. }
  30. public static function testSuccess()
  31. {
  32. $model_order = Model('order');
  33. $logic_order = Logic('order');
  34. $condition = array();
  35. $condition['order_state'] = ORDER_STATE_SEND;
  36. $condition['lock_state'] = 0;
  37. //$condition['delay_time'] = array('lt',time() - ORDER_AUTO_RECEIVE_DAY * 86400);
  38. $condition['order_id'] = 6591;
  39. //分批,每批处理100个订单,最多处理5W个订单
  40. $order_list = $model_order->getOrderList($condition, '', '*', 'delay_time asc', 100);
  41. foreach ($order_list as $order_info) {
  42. $result = $logic_order->changeOrderStateReceive($order_info,'system','系统','超期未收货系统自动完成订单');
  43. }
  44. }
  45. public function testSend()
  46. {
  47. $order_sn = '9000000001035202';
  48. $status = 1;
  49. $consign_time = '2017-01-15 18:07:05.0';
  50. $logistics_no = '3322415835338';
  51. $logistics_company = '申通快递';
  52. $express = Model('express')->field('id')->where(array('e_name' => $logistics_company))->select();
  53. if (empty($express) || count($express) == 0) {
  54. echo 'FAIL';
  55. return;
  56. }
  57. $express_id = $express[0]['id'];
  58. $time = strtotime($consign_time);
  59. }
  60. public function testInitOrder()
  61. {
  62. $mod_member = Model('member');
  63. $i = 0;
  64. while (true)
  65. {
  66. $start = $i * 1000;
  67. $items = Model()->table('member')->field('member_id')->order('member_id asc')->limit("{$start},1000")->select();
  68. if(empty($items)) {
  69. return;
  70. }
  71. $i++;
  72. foreach ($items as $item)
  73. {
  74. $member_id = intval($item['member_id']);
  75. if($member_id <= 0) continue;
  76. $result = $this->stat_order($member_id);
  77. if($result == false) continue;
  78. $order_num = intval($result['order_num']);
  79. $lasted_time = intval($result['lastest_time']);
  80. $mod_member->editMember(['member_id' => $member_id],['order_num' => $order_num,'lastest_order' => $lasted_time]);
  81. }
  82. }
  83. }
  84. private function stat_order($member_id)
  85. {
  86. $items = Model()->table('order')
  87. ->field('count(*) as order_num,max(payment_time) lastest_time')
  88. ->where(['buyer_id' => $member_id,'order_state' => ['in',[20,30,40]]])
  89. ->select();
  90. if(empty($items)) {
  91. return false;
  92. }
  93. elseif($items[0]['order_num'] == 0){
  94. return false;
  95. } else {
  96. return $items[0];
  97. }
  98. }
  99. public function testMemberOrder()
  100. {
  101. $mod_member = Model('member');
  102. $this->mStartm = strtotime(date('Y-m-d',time()));
  103. $this->mEndtm = $this->mStartm + 86400 - 1;
  104. $cond['payment_time'] = ['between',"{$this->mStartm},{$this->mEndtm}"];
  105. $cond['order_state'] = array('in',[20,30,40]);
  106. $i = 0;
  107. while (true)
  108. {
  109. $start = $i * 1000;
  110. $items = Model()->table('order')->field('buyer_id,payment_time')->where($cond)->order('payment_time asc')->limit("{$start},1000")->select();
  111. if(empty($items)) {
  112. return;
  113. }
  114. $i++;
  115. foreach ($items as $item)
  116. {
  117. $member_id = intval($item['buyer_id']);
  118. if($member_id <= 0) continue;
  119. $payment_time = intval($item['payment_time']);
  120. if($payment_time <= 0) continue;
  121. $mod_member->editMember(['member_id' => $member_id],['order_num' => ['exp', 'order_num+1'],'lastest_order' => $payment_time]);
  122. }
  123. }
  124. }
  125. public function testStatCall()
  126. {
  127. $x = 'a:4:{s:8:"function";a:16:{s:10:"app_update";a:2:{s:13:"check_version";a:1:{s:5:"count";i:7;}s:4:"area";a:1:{s:5:"count";i:7;}}s:6:"config";a:1:{s:11:"getconfigex";a:1:{s:5:"count";i:9;}}s:11:"member_info";a:2:{s:3:"get";a:1:{s:5:"count";i:7;}s:4:"edit";a:1:{s:5:"count";i:1;}}s:7:"special";a:1:{s:5:"index";a:1:{s:5:"count";i:10;}}s:5:"index";a:2:{s:6:"splash";a:1:{s:5:"count";i:8;}s:4:"tabs";a:1:{s:5:"count";i:8;}}s:5:"login";a:1:{s:6:"status";a:1:{s:5:"count";i:8;}}s:12:"member_order";a:1:{s:15:"orderCountState";a:1:{s:5:"count";i:5;}}s:12:"member_bonus";a:1:{s:5:"topup";a:1:{s:5:"count";i:16;}}s:13:"member_logout";a:1:{s:5:"index";a:1:{s:5:"count";i:2;}}s:14:"member_address";a:1:{s:12:"address_list";a:1:{s:5:"count";i:1;}}s:7:"bonusex";a:1:{s:4:"open";a:1:{s:5:"count";i:2;}}s:6:"search";a:3:{s:13:"suggest_words";a:1:{s:5:"count";i:4;}s:5:"index";a:1:{s:5:"count";i:7;}s:7:"history";a:1:{s:5:"count";i:1;}}s:12:"goods_common";a:1:{s:5:"index";a:1:{s:5:"count";i:2;}}s:5:"fcode";a:2:{s:5:"index";a:1:{s:5:"count";i:4;}s:4:"open";a:1:{s:5:"count";i:4;}}s:5:"mshop";a:1:{s:7:"signurl";a:1:{s:5:"count";i:3;}}s:4:"cart";a:2:{s:5:"addex";a:1:{s:5:"count";i:1;}s:10:"rate_money";a:1:{s:5:"count";i:1;}}}s:5:"other";a:3:{s:10:"goods_4919";a:1:{s:5:"count";i:1;}s:10:"goods_6212";a:1:{s:5:"count";i:1;}s:11:"special_466";a:1:{s:5:"count";i:1;}}s:9:"app_count";i:107;s:9:"wap_count";i:11;}';
  128. $y = unserialize($x);
  129. $x = json_encode($y);
  130. $x = json_decode($x,true);
  131. }
  132. public function testBonusRate()
  133. {
  134. $data = 'a:2:{i:50;d:5.1799999999999997;i:30;d:17.59;}';
  135. $x = unserialize($data);
  136. }
  137. public function testRefund()
  138. {
  139. //SELECT * FROM lrlz_order WHERE add_time > UNIX_TIMESTAMP(DATE ('2017-09-28 00:00:00')) AND order_state = 0;
  140. $items = Model()->query('SELECT * FROM lrlz_order WHERE pd_amount=0 AND LENGTH(bonus_rate) > 0 AND add_time > UNIX_TIMESTAMP(DATE (\'2017-09-01 00:00:00\')) AND order_state = 0');
  141. foreach ($items as $item) {
  142. $order_sn = $item['order_sn'];
  143. $member_id = intval($item['buyer_id']);
  144. account_helper::order_cancel($order_sn,$member_id,true);
  145. }
  146. }
  147. ////
  148. public function testVOrder()
  149. {
  150. $model_vr_order = Model('vr_order');
  151. $order_list = $model_vr_order->getOrderList(['order_id' => 1]);
  152. $page_count = $model_vr_order->gettotalpage();
  153. $helper = new vorder_helper($order_list);
  154. $result = $helper->format();
  155. }
  156. public function testUpdateVOrder()
  157. {
  158. $order_sn = '730652395243593640';
  159. $payer = new pay_helper($order_sn);
  160. $trade_no = '730510765598547589';
  161. $cb_info = $payer->update_order($trade_no,'wxpay');
  162. }
  163. public function testBonusAmount()
  164. {
  165. $mod_order = Model('order');
  166. $i = 0;
  167. while (true)
  168. {
  169. $start = $i * 1000;
  170. $items = $mod_order->table('order')->field('*')->order('order_id asc')->limit("{$start},1000")->select();
  171. if(empty($items)) {
  172. return;
  173. }
  174. $i++;
  175. foreach ($items as $item)
  176. {
  177. $order_id = intval($item['order_id']);
  178. $pd_amount = intval($item['pd_amount'] * 100 + 0.5);
  179. $bonus_rate = unserialize($item['bonus_rate']);
  180. $bonus_amount = unserialize($item['bonus_amount']);
  181. if($bonus_amount != false) continue;
  182. $data = [];
  183. if($bonus_rate != false)
  184. {
  185. $amount = 0;
  186. foreach ($bonus_rate as $rate => $money) {
  187. $amount += $money;
  188. }
  189. $data['bonus_amount'] = serialize(['user_bonus' => $amount]);
  190. }
  191. elseif($pd_amount > 0) {
  192. $data['bonus_amount'] = serialize(['user_bonus' => $pd_amount / 100]);
  193. }
  194. else {
  195. }
  196. $data['bonus_rate'] = '';
  197. $data['pd_amount'] = 0.00;
  198. $mod_order->editOrder($data,['order_id' => $order_id]);
  199. }
  200. }
  201. }
  202. public function testQueryOrder()
  203. {
  204. $delivery = Logic('delivery');
  205. $order_sn = '2000000004387603';
  206. $status = $delivery->query_order($order_sn);
  207. $time = $status->send_time();
  208. }
  209. public function testCancelOrder()
  210. {
  211. $delivery = Logic('delivery');
  212. $order_sn = '2000000004385101';
  213. $status = $delivery->cancel_order($order_sn);
  214. }
  215. }