TestController.php 15 KB

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