TestController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Authority;
  4. use App\Batch;
  5. use App\Commodity;
  6. use App\CommodityBarcode;
  7. use App\CommodityMaterialBoxModel;
  8. use App\Components\AsyncResponse;
  9. use App\Components\Database;
  10. use App\Components\ErrorPush;
  11. use App\ErrorTemp;
  12. use App\Feature;
  13. use App\Http\ApiControllers\LoginController;
  14. use App\Http\Controllers\api\thirdPart\haochuang\SortingController;
  15. use App\Http\Controllers\api\thirdPart\syrius\beans\StorageTypeCell;
  16. use App\Http\Controllers\api\thirdPart\syrius\beans\StorageTypeRelation;
  17. use App\Http\Controllers\api\thirdPart\syrius\beans\Task;
  18. use App\Http\Controllers\api\thirdPart\syrius\beans\TaskItem;
  19. use App\Http\Controllers\api\thirdPart\syrius\producer\StorageTypeController;
  20. use App\Http\Controllers\api\thirdPart\syrius\units\Signature;
  21. use App\Http\Controllers\api\thirdPart\syrius\units\StorageTypeAttribute;
  22. use App\Http\Requests\AndroidGateRequest;
  23. use App\Http\Requests\OrderDelivering;
  24. use App\InventoryAccount;
  25. use App\InventoryAccountMission;
  26. use App\Jobs\BatchTaskJob;
  27. use App\Jobs\BroadcastBatchToZhengCangJob;
  28. use App\Jobs\CacheShelfTaskJob;
  29. use App\Jobs\OrderCreateInstantBill;
  30. use App\Jobs\OrderCreateWaybill;
  31. use App\Jobs\SettlementBillReportJob;
  32. use App\Jobs\StoreCreateInstantBill;
  33. use App\Jobs\TestJob;
  34. use App\Jobs\WeightUpdateInstantBill;
  35. use App\LaborCompanyDispatch;
  36. use App\LaborReport;
  37. use App\LaborReportStatus;
  38. use App\Logistic;
  39. use App\MaterialBox;
  40. use App\MaterialBoxModel;
  41. use App\Notifications\RoutineNotification;
  42. use App\Observers\WaybillObserver;
  43. use App\OracleDOCASNDetail;
  44. use App\OracleDOCASNHeader;
  45. use App\OracleDOCOrderHeader;
  46. use App\OracleDocOrderPackingSummary;
  47. use App\OracleDOCWaveDetails;
  48. use App\Order;
  49. use App\OrderBin;
  50. use App\OrderCommodity;
  51. use App\OrderIssue;
  52. use App\OrderIssueProcessLog;
  53. use App\OrderIssueType;
  54. use App\OrderPackage;
  55. use App\Owner;
  56. use App\OwnerAreaReport;
  57. use App\OwnerBillReport;
  58. use App\OwnerFeeDetail;
  59. use App\OwnerFeeDetailLogistic;
  60. use App\OwnerFeeExpress;
  61. use App\OwnerFeeLogistic;
  62. use App\OwnerFeeOperation;
  63. use App\OwnerFeeOperationDetail;
  64. use App\OwnerFeeStorage;
  65. use App\OwnerPriceExpress;
  66. use App\OwnerPriceOperation;
  67. use App\OrderPackageCountingRecord;
  68. use App\OwnerReport;
  69. use App\ProcurementCheckSheet;
  70. use App\ProcurementDeliverie;
  71. use App\ReceiveRecord;
  72. use App\RejectedBill;
  73. use App\SeeLog;
  74. use App\Services\AndroidInventoryService;
  75. use App\Services\AuthorityService;
  76. use App\Services\BatchService;
  77. use App\Services\CacheShelfService;
  78. use App\Services\common\BatchUpdateService;
  79. use App\Services\ForeignHaiRoboticsService;
  80. use App\Services\ForeignZhenCangService;
  81. use App\Services\LogisticService;
  82. use App\Services\LogService;
  83. use App\Services\MenuService;
  84. use App\Services\NotificationService;
  85. use App\Services\OracleDOCOrderHeaderService;
  86. use App\Services\OrderPackageCommoditiesService;
  87. use App\Services\OrderPackageReceivedSyncService;
  88. use App\Services\OrderPackageService;
  89. use App\Services\OrderService;
  90. use App\Services\OrderTrackingService;
  91. use App\Services\OwnerFeeTotalService;
  92. use App\Services\OwnerLogisticFeeReportService;
  93. use App\Services\OwnerPriceOperationService;
  94. use App\Services\OwnerService;
  95. use App\Services\OwnerStoreFeeReportService;
  96. use App\Services\OwnerStoreOutFeeReportService;
  97. use App\Services\ReplenishmentService;
  98. use App\Services\ReviewService;
  99. use App\Services\StationService;
  100. use App\Services\StorageService;
  101. use App\Services\StoreItemService;
  102. use App\Services\StoreService;
  103. use App\Services\SyriusTaskService;
  104. use App\Services\UserService;
  105. use App\Services\WorkOrderService;
  106. use App\SortingStation;
  107. use App\Station;
  108. use App\StationTask;
  109. use App\StationTaskMaterialBox;
  110. use App\Store;
  111. use App\StoreItem;
  112. use App\TaskTransaction;
  113. use App\Unit;
  114. use App\User;
  115. use App\UserDetail;
  116. use App\UserDutyCheck;
  117. use App\ValueStore;
  118. use App\Waybill;
  119. use App\WorkOrder;
  120. use App\WorkOrderCommodities;
  121. use App\WorkOrderDetail;
  122. use App\WorkOrderImage;
  123. use App\WorkOrderLog;
  124. use Carbon\Carbon;
  125. use Carbon\CarbonPeriod;
  126. use Decimal\Decimal;
  127. use Doctrine\DBAL\Driver\AbstractDB2Driver;
  128. use Doctrine\DBAL\Exception;
  129. use Firebase\JWT\ExpiredException;
  130. use Firebase\JWT\JWT;
  131. use Illuminate\Database\Eloquent\Builder;
  132. use Illuminate\Database\Eloquent\Collection;
  133. use Illuminate\Database\Eloquent\HigherOrderBuilderProxy;
  134. use Illuminate\Database\Eloquent\Model;
  135. use Illuminate\Database\QueryException;
  136. use Illuminate\Foundation\Http\FormRequest;
  137. use Illuminate\Http\Request;
  138. use Illuminate\Support\Facades\Broadcast;
  139. use Illuminate\Support\Facades\Cache;
  140. use Illuminate\Support\Facades\Auth;
  141. use Illuminate\Support\Facades\Cookie;
  142. use Illuminate\Support\Facades\DB;
  143. use Illuminate\Support\Facades\Hash;
  144. use Illuminate\Support\Facades\Http;
  145. use Illuminate\Support\Facades\Log;
  146. use Illuminate\Support\Facades\Notification;
  147. use Illuminate\Support\Facades\URL;
  148. use Illuminate\Support\Facades\Validator;
  149. use Illuminate\Support\Str;
  150. use Laravel\Horizon\Events\JobFailed;
  151. use Monolog\Handler\IFTTTHandler;
  152. use phpDocumentor\Reflection\Types\Resource_;
  153. use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
  154. use PhpParser\Node\Stmt\DeclareDeclare;
  155. use Ramsey\Uuid\Uuid;
  156. use Symfony\Component\ErrorHandler\Error\FatalError;
  157. class TestController extends Controller
  158. {
  159. use AsyncResponse, ErrorPush, Database;
  160. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  161. public function __construct()
  162. {
  163. $this->data["active_test"] = "active";
  164. }
  165. public function method(Request $request, $method)
  166. {
  167. try {
  168. return call_user_func([$this, $method], $request);
  169. }catch (\BadMethodCallException $e){
  170. dd("方法不存在");
  171. }
  172. }
  173. public function test1(\Closure $c,string $a){
  174. dd($c($a));
  175. }
  176. private function paramDefault(&$waybill):array
  177. {
  178. $update = [];
  179. if (!$waybill->order_type){
  180. $update["order_type"] = $waybill->order_type = Waybill::ORDER_TYPE_DEFAULT;
  181. }
  182. if (!$waybill->transport_type){
  183. $update["transport_type"] = $waybill->transport_type = "JZKH";
  184. }
  185. if (!$waybill->cargo_name){
  186. $update["cargo_name"] = $waybill->cargo_name = "补货";
  187. }
  188. if (!$waybill->total_number){
  189. $update["total_number"] = $waybill->total_number = 1;
  190. }
  191. if (!$waybill->total_weight){
  192. $update["total_weight"] = $waybill->total_weight = 1;
  193. }
  194. if (!$waybill->package_service){
  195. $update["package_service"] = $waybill->package_service = '托膜';
  196. }
  197. if (!$waybill->deliveryType){
  198. $update["deliveryType_id"] = $waybill->deliveryType_id = 3;
  199. }
  200. if (!$waybill->pay_type){
  201. $update["pay_type"] = $waybill->pay_type = Waybill::PAY_TYPE_DEFAULT;
  202. }
  203. if (!$waybill->back_sign_bill){
  204. $update["back_sign_bill"] = $waybill->back_sign_bill = Waybill::BACK_SIGN_BILL_DEFAULT;
  205. }
  206. return $update;
  207. }
  208. /**
  209. * @param Model|\stdClass $waybill
  210. */
  211. private function formatWaybillData($waybill):array
  212. {
  213. $waybill->loadMissing([
  214. "order.shop","owner","order.warehouse.province","order.warehouse.city","order.warehouse.county"
  215. ]);
  216. $date = date('Y-m-d H:i:s', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp());
  217. $data = [
  218. 'logisticID' => config('api_logistic.DB.prod.sign').date("YmdHis").mt_rand(1000, 9999).$waybill->order->id,
  219. 'custOrderNo' => $waybill->order->client_code ?? '',
  220. 'needTraceInfo' => config('api_logistic.DB.prod.needTraceInfo'),
  221. 'companyCode' => config('api_logistic.DB.prod.company_code'),
  222. 'orderType' => $waybill->order_type,
  223. 'transportType' => $waybill->transport_type,
  224. 'customerCode' => config('api_logistic.DB.prod.customer_Code'),
  225. 'sender' => [
  226. 'companyName' => '宝时物流',
  227. 'businessNetworkNo' => '',
  228. 'name' => '宝时物流',
  229. 'mobile' => '',
  230. 'phone' => '021-6316561',
  231. 'province' => $waybill->order->warehouse->province->name ?? '',
  232. 'city' => $waybill->order->warehouse->city->name ?? '',
  233. 'country' => $waybill->order->warehouse->county->name ?? '',
  234. 'town' => '',
  235. 'address' => $waybill->order->warehouse->address ?? '',
  236. ],
  237. 'receiver' => [
  238. 'toNetworkNo' => '',
  239. 'name' => $waybill->order->consignee_name ?? '',
  240. 'phone' => $waybill->order->consignee_phone ?? '',
  241. 'mobile' => $waybill->order->consignee_phone ?? '',
  242. 'province' => $waybill->order->province ?? '',
  243. 'city' => $waybill->order->city ?? "",
  244. 'county' => $waybill->order->district ?? '',
  245. 'town' => '',
  246. 'address' => $waybill->order->address ?? '',
  247. 'companyName' => ''
  248. ],
  249. 'packageInfo' => [
  250. 'cargoName' => $waybill->cargo_name ?? '',
  251. 'totalNumber' => $waybill->total_number ?? '',
  252. 'totalWeight' => $waybill->total_weight ?? '',
  253. 'totalVolume' => '',
  254. 'packageService' => $waybill->package_service ?? '',
  255. 'deliveryType' => $waybill->deliveryType_id,
  256. ],
  257. 'gmtCommit' => $date,
  258. 'payType' => $waybill->pay_type,
  259. 'addServices' => [
  260. 'insuranceValue' => '',
  261. 'codType' => '',
  262. 'reciveLoanAccount' => '',
  263. 'accountName' => '',
  264. 'codValue' => '',
  265. 'backSignBill' => $waybill->back_sign_bill
  266. ],
  267. 'smsNotify' => config('api_logistic.DB.prod.smsNotify'),
  268. 'sendStartTime' => $date,
  269. 'sendEndTime' => date('Y-m-d ', $waybill->deliver_at ? strtotime($waybill->deliver_at) : now()->getTimestamp()).'23:59:59',
  270. 'originalWaybillNumber' => $waybill->wms_bill_number ?? '',
  271. 'remark' => $waybill->dispatch_remark ?? '',
  272. 'isOut' => 'N',
  273. 'passwordSigning' => config('api_logistic.DB.prod.passwordSigning'),
  274. 'isdispatched' => '',
  275. 'ispresaleorder'=> '',
  276. 'isCenterDelivery' => '',
  277. // 'orderExtendFields' => [
  278. // 'value' => '',
  279. // 'key' => ''
  280. // ]
  281. ];
  282. $param = json_encode($data);
  283. $timestamp = (integer)getMillisecond();
  284. return ["params"=>$param,"timestamp"=>$timestamp,
  285. "digest"=>base64_encode(md5($param.config('api_logistic.DB.prod.app_key').$timestamp)),
  286. "companyCode" => config('api_logistic.DB.prod.company_code')];
  287. }
  288. public function test(Request $request)
  289. {
  290. $waybill = Waybill::query()->where("waybill_number","BSDB2112284814")
  291. ->first();
  292. $waybill->load("order");
  293. if (!$waybill->order){
  294. dd("德邦单号获取失败1");
  295. return;
  296. }
  297. $update = $this->paramDefault($waybill);
  298. $waybill->update($update);
  299. $bill = app('DbOpenService')->getDbOrderNo($waybill);
  300. if (!$bill || $bill["result"]=="false"){
  301. dd($bill);
  302. return;
  303. }
  304. $waybill->update([
  305. "carrier_bill"=>$bill['mailNo'],
  306. "waybill_number"=>$bill['mailNo'],
  307. "station_no"=>$bill['stationNo'],
  308. "arrived_org_simple_name"=>$bill['arrivedOrgSimpleName'],
  309. "much_higher_delivery"=>$bill['muchHigherDelivery'],
  310. ]);
  311. if (!app("WaybillService")->notifyFlux($waybill)){
  312. dd("德邦单号回传FLUX失败");
  313. return;
  314. }
  315. dd(1);
  316. $c = "test";
  317. $a = function ($b)use($c){
  318. return $b.$c;
  319. };
  320. $this->test1($a,"a");
  321. dd(2);
  322. $w = Waybill::query()->get();
  323. foreach ($w->chunk(50) as $a){
  324. dd($a);
  325. }
  326. $path = '';
  327. $id = 252;
  328. $file = fopen($path, "r");
  329. $user=array();
  330. $i=0;
  331. //输出文本中所有的行,直到文件结束为止。
  332. while(! feof($file)){
  333. $user[$i]= trim(fgets($file));//fgets()函数从文件指针中读取一行
  334. $i++;
  335. }
  336. fclose($file);
  337. foreach ($user as $item){
  338. $arr = explode(",",$item);
  339. if (count($arr)!=2){
  340. dump($item);
  341. continue;
  342. }
  343. DB::table("details")->insert([
  344. "name" => $arr[0],
  345. "size" => $arr[1],
  346. "created_at" => date("Y-m-d H:i:s"),
  347. "updated_at" => date("Y-m-d H:i:s"),
  348. "header_id" => $id
  349. ]);
  350. }
  351. }
  352. public function test123(){
  353. $rejected_bill = RejectedBill::query()->find(2);
  354. $service = new WorkOrderService();
  355. $service->syncWorkOrder($rejected_bill);
  356. }
  357. public function assignBatch($code)
  358. {
  359. $batches = Batch::query()->where("code",$code)->get();
  360. if (!$batches->count()){
  361. $wave = DB::connection("oracle")->selectOne(DB::raw("select * from DOC_WAVE_HEADER where WAVENO = ?"),[$code]);
  362. if (!$wave){
  363. dd("FLUX无波次");
  364. }
  365. $owner = app("OwnerService")->codeGetOwner($wave->customerid);
  366. $obj = [
  367. "wms_status" => $this->wms_status($wave),
  368. "wms_type"=>$wave->descr,
  369. "created_at"=>date("Y-m-d H:i:s"),
  370. "wms_created_at"=>$wave->addtime,
  371. "updated_at"=>$wave->edittime,
  372. "owner_id"=>$owner->id,
  373. ];
  374. $wave = Batch::query()->where("code",$code)->first();
  375. if (!$wave){
  376. $obj["code"] = $code;
  377. $wave = Batch::query()->create($obj);
  378. }else{
  379. Batch::query()->where("code",$code)->update($obj);
  380. }
  381. $ordernos = array_column(DB::connection("oracle")->select(DB::raw("select orderno from DOC_WAVE_DETAILS where WAVENO = ?"),[$code]),"orderno");
  382. Order::query()->whereIn("code",$ordernos)->update([
  383. "batch_id"=>$wave->id
  384. ]);
  385. Order::query()->with(["batch","bin"])->whereIn("code",$ordernos)->get()->each(function ($order){
  386. if (!$order->bin){
  387. $bin = DB::connection("oracle")->selectOne(DB::raw("select seqno from DOC_WAVE_DETAILS where waveno = ? and orderno = ?"),[$order->batch->code,$order->code]);
  388. if ($bin){
  389. OrderBin::query()->create([
  390. 'order_id' => $order->id,
  391. 'number' => $bin->seqno,
  392. ]);
  393. }
  394. }
  395. });
  396. $batches = Batch::query()->where("code",$code)->get();
  397. }
  398. app("BatchService")->assignTasks($batches);
  399. }
  400. }