LogisticZopSyncTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Jobs\LogisticZopSync;
  4. use App\Order;
  5. use App\OrderPackage;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Foundation\Testing\RefreshDatabase;
  8. use Illuminate\Foundation\Testing\WithFaker;
  9. use Tests\TestCase;
  10. class LogisticZopSyncTest extends TestCase
  11. {
  12. protected $order;
  13. /**
  14. * A basic feature test example.
  15. *
  16. * @return void
  17. */
  18. // public function testExample()
  19. // {
  20. // LogisticZopSync::dispatch('73228022760994');
  21. // }
  22. protected function setUp(): void
  23. {
  24. parent::setUp(); // TODO: Change the autogenerated stub
  25. }
  26. protected function tearDown(): void
  27. {
  28. OrderPackage::query()->where('logistic_number', '000000111')->delete();
  29. $this->order && $this->order->delete();
  30. parent::tearDown(); // TODO: Change the autogenerated stub
  31. }
  32. public function test_get()
  33. {
  34. LogisticZopSync::dispatch('75806876414856');
  35. }
  36. /**
  37. * @test
  38. */
  39. public function transformRoutes疑似库内丢件Test()
  40. {
  41. $order = factory(Order::class)->create(['province' => '上海']);
  42. $this->order = $order;
  43. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5),'order_id' => $order->id]);
  44. $logisticZopSync = new LogisticZopSync('000000111');
  45. $data[] = [
  46. 'routes' => [
  47. ],
  48. "logisticNum" => "000000111",
  49. ];
  50. $result = $logisticZopSync->transformRoutes($data);
  51. $this->assertEquals('疑似库内丢件', $result[0]['exception_type']);
  52. }
  53. /**
  54. * @test
  55. */
  56. public function transformRoutes中转异常Test()
  57. {
  58. $order = factory(Order::class)->create(['province' => '上海']);
  59. $this->order = $order;
  60. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
  61. $logisticZopSync = new LogisticZopSync('000000111');
  62. $data[] = [
  63. 'routes' => [
  64. json_decode($this->itemScanDate25hBefore()),
  65. ],
  66. "logisticNum" => "000000111",
  67. ];
  68. $result = $logisticZopSync->transformRoutes($data);
  69. $this->assertEquals('中转异常', $result[0]['exception_type']);
  70. }
  71. /**
  72. * @test
  73. */
  74. public function transformRoutes疑似丢件Test()
  75. {
  76. $order = factory(Order::class)->create(['province' => '上海']);
  77. $this->order = $order;
  78. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
  79. $logisticZopSync = new LogisticZopSync('000000111');
  80. $data[] = [
  81. 'routes' => [
  82. json_decode($this->itemScanDate73hBefore()),
  83. ],
  84. "logisticNum" => "000000111",
  85. ];
  86. $result = $logisticZopSync->transformRoutes($data);
  87. $this->assertEquals('疑似丢件', $result[0]['exception_type']);
  88. }
  89. /**
  90. * @test
  91. */
  92. public function transformRoutes派送异常Test()
  93. {
  94. $order = factory(Order::class)->create(['province' => '上海']);
  95. $this->order = $order;
  96. factory(OrderPackage::class)->create(['logistic_number' => '000000111', 'sent_at' => now()->subHours(5), 'order_id' => $order->id]);
  97. $logisticZopSync = new LogisticZopSync('000000111');
  98. $data[] = [
  99. 'routes' => [
  100. json_decode($this->itemScanDate49hBefore()),
  101. ],
  102. "logisticNum" => "000000111",
  103. ];
  104. $result = $logisticZopSync->transformRoutes($data);
  105. $this->assertEquals('派件异常', $result[0]['exception_type']);
  106. }
  107. /**
  108. * @return false|string
  109. */
  110. private function itemScanDate25hBefore()
  111. {
  112. return json_encode([
  113. 'country' => 'China',
  114. 'signMan' => null,
  115. 'operateUserPhone' => '17717571635',
  116. 'weight' => null,
  117. 'billCode' => null,
  118. 'operateUserCode' => '02141',
  119. 'preOrNextSite' => null,
  120. 'scanDate' => now()->subHours(25)->getTimestamp() * 1000,
  121. 'scanSite' => [
  122. 'isCenter' => 'F',
  123. 'code' => '02141',
  124. 'isTransfer' => 0,
  125. 'phone' => '60664064',
  126. 'city' => '""',
  127. 'name' => '九亭',
  128. 'siteId' => '2745',
  129. 'id' => '2745',
  130. 'prov' => '上海',
  131. ],
  132. 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
  133. 'operateUser' => '笔记本',
  134. 'scanType' => '收件',
  135. ]);
  136. }
  137. /**
  138. * @return false|string
  139. */
  140. private function itemScanDate73hBefore()
  141. {
  142. return json_encode([
  143. 'country' => 'China',
  144. 'signMan' => null,
  145. 'operateUserPhone' => '17717571635',
  146. 'weight' => null,
  147. 'billCode' => null,
  148. 'operateUserCode' => '02141',
  149. 'preOrNextSite' => null,
  150. 'scanDate' => now()->subHours(73)->getTimestamp() * 1000,
  151. 'scanSite' => [
  152. 'isCenter' => 'F',
  153. 'code' => '02141',
  154. 'isTransfer' => 0,
  155. 'phone' => '60664064',
  156. 'city' => '""',
  157. 'name' => '九亭',
  158. 'siteId' => '2745',
  159. 'id' => '2745',
  160. 'prov' => '上海',
  161. ],
  162. 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
  163. 'operateUser' => '笔记本',
  164. 'scanType' => '收件',
  165. ]);
  166. }
  167. /**
  168. * @return false|string
  169. */
  170. private function itemScanDate49hBefore()
  171. {
  172. return json_encode([
  173. 'country' => 'China',
  174. 'signMan' => null,
  175. 'operateUserPhone' => '17717571635',
  176. 'weight' => null,
  177. 'billCode' => null,
  178. 'operateUserCode' => '02141',
  179. 'preOrNextSite' => null,
  180. 'scanDate' => now()->subHours(49)->getTimestamp() * 1000,
  181. 'scanSite' => [
  182. 'isCenter' => 'F',
  183. 'code' => '02141',
  184. 'isTransfer' => 0,
  185. 'phone' => '60664064',
  186. 'city' => '""',
  187. 'name' => '九亭',
  188. 'siteId' => '2745',
  189. 'id' => '2745',
  190. 'prov' => '上海',
  191. ],
  192. 'extend' => "{'optReasonEn':'Parcel scanned by site'}",
  193. 'operateUser' => '笔记本',
  194. 'scanType' => '派件',
  195. ]);
  196. }
  197. /**
  198. * @return false|string
  199. */
  200. private function item2()
  201. {
  202. return json_encode([]);
  203. }
  204. /**
  205. * @test
  206. */
  207. public function arr_test()
  208. {
  209. $data = [];
  210. $data['aa'] = "vbbb";
  211. dd(array_key_exists('aa',$data));
  212. }
  213. }