LogisticZopSyncTest.php 6.8 KB

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