LogisticZopSyncTest.php 6.9 KB

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