TestController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Batch;
  4. use App\Commodity;
  5. use App\CommodityMaterialBoxModel;
  6. use App\Components\AsyncResponse;
  7. use App\Components\ErrorPush;
  8. use App\ErrorTemp;
  9. use App\Feature;
  10. use App\Jobs\CacheShelfTaskJob;
  11. use App\Jobs\OrderCreateWaybill;
  12. use App\MaterialBox;
  13. use App\MaterialBoxModel;
  14. use App\Order;
  15. use App\Owner;
  16. use App\OwnerFeeDetail;
  17. use App\OwnerPriceOperation;
  18. use App\OrderPackageCountingRecord;
  19. use App\RejectedBill;
  20. use App\Services\ForeignHaiRoboticsService;
  21. use App\Services\ForeignZhenCangService;
  22. use App\Services\StationService;
  23. use App\Services\StorageService;
  24. use App\Station;
  25. use App\StationTask;
  26. use App\StationTaskMaterialBox;
  27. use App\TaskTransaction;
  28. use App\Unit;
  29. use App\Waybill;
  30. use Carbon\Carbon;
  31. use Carbon\CarbonPeriod;
  32. use Illuminate\Database\Eloquent\Collection;
  33. use Illuminate\Http\Request;
  34. use Illuminate\Support\Facades\Cache;
  35. use Illuminate\Support\Facades\Auth;
  36. use Illuminate\Support\Facades\Cookie;
  37. use Illuminate\Support\Facades\DB;
  38. use Illuminate\Support\Facades\Http;
  39. class TestController extends Controller
  40. {
  41. use AsyncResponse,ErrorPush;
  42. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  43. private $data = [];
  44. public function __construct()
  45. {
  46. $this->data["active_test"] = "active";
  47. }
  48. public function method(Request $request, $method)
  49. {
  50. return call_user_func([$this, $method], $request);
  51. }
  52. public function lightUp()
  53. {
  54. app("CacheShelfService")->lightUp('HAIB1-02-02','3','0');
  55. }
  56. public function lightOff()
  57. {
  58. $params = [
  59. "areaCode" => "1004",
  60. 'locCode' => "HAIB1-02-02",
  61. 'PTLAction' => 0,
  62. ];
  63. $response = Http::post(config('api.haiq.storage.light'), $params);
  64. return json_decode($response->body());
  65. }
  66. public function test()
  67. {
  68. app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-01");
  69. app("CacheShelfService")->_stationCacheLightOff("HAIB1-01-02");
  70. app("CacheShelfService")->_stationCacheLightOff("HAIB1-02-02");
  71. dd(1);
  72. $stationTaskMaterialBox = StationTaskMaterialBox::query()->find(70370);
  73. DB::beginTransaction();
  74. try{
  75. $stationTaskMaterialBox->loadMissing("station");
  76. //如果为半箱位置 清理原有任务
  77. if (!$stationTaskMaterialBox->station)return;
  78. if (app("StationService")->isHalfBoxLocation($stationTaskMaterialBox->station)){
  79. app("StationService")->locationOccupy($stationTaskMaterialBox->station->code,$stationTaskMaterialBox->material_box_id);
  80. //清除海柔库位信息
  81. app("StorageService")->clearTask([$stationTaskMaterialBox->station->code]);
  82. $stationId = $stationTaskMaterialBox->station_id;
  83. $tasks = TaskTransaction::query()->with("materialBox")->where(function ($query)use($stationId){
  84. $query->where("fm_station_id",$stationId)->orWhere("to_station_id",$stationId);
  85. })->where("status",0)->get();
  86. if ($tasks->count()!=0){
  87. $options = [];
  88. switch ($tasks[0]->mark){
  89. case 1:
  90. $options["title"] = '上架任务';
  91. break;
  92. case 2:
  93. $options["title"] = '出库任务';
  94. break;
  95. default:
  96. $options["title"] = '未知类型';
  97. }
  98. switch ($tasks->count()){
  99. case 1:
  100. $task = $tasks[0];
  101. $options["detail01"] = $task->materialBox->code ?? '';
  102. $options["detail02"] = $task->doc_code ?: '跟踪:‘'.$task->track_num."’ 批次:‘".$task->lot_num."’";
  103. $options["detail03"] = $task->bar_code;
  104. $options["qty01"] = $task->amount;
  105. $options["uomDesc01"] = '件';
  106. $options["qty02"] = $task->bin_number;
  107. $options["uomDesc02"] = '号';
  108. break;
  109. default:
  110. $count = count(array_unique(array_column($tasks->toArray(),"commodity_id")));
  111. if ($count==1){
  112. $options["detail01"] = $tasks[0]->bar_code;
  113. $options["detail02"] = "";
  114. $options["detail03"] = "";
  115. $amount = 0;
  116. foreach ($tasks as $task){
  117. if (mb_strlen($options["detail02"])>20){
  118. $options["detail03"] .= $task->bin_number."号-".$task->amount."件,";
  119. }else $options["detail02"] .= $task->bin_number."号-".$task->amount."件,";
  120. $amount += $task->amount;
  121. }
  122. $options["detail02"] = rtrim($options["detail02"],",");
  123. $options["detail03"] = rtrim($options["detail03"],",");
  124. $options["qty02"] = $amount;
  125. $options["uomDesc02"] = '件';
  126. }else{
  127. $task = $tasks[0];
  128. $options["detail01"] = $task->materialBox->code ?? '';
  129. $options["detail02"] = "货品过多请自行核对";
  130. $options["detail03"] = "波次:".$task->doc_code ?
  131. (Order::query()->with("batch")->where("code",$task->doc_code)->first()->batch->code ?? '无') : '无';
  132. }
  133. break;
  134. }
  135. app("CacheShelfService")->lightUp($stationTaskMaterialBox->station->code,'2','0',$options);
  136. Cache::forget("CACHE_SHELF_OCCUPANCY_{$stationTaskMaterialBox->station->id}");//关闭无限亮灯
  137. }
  138. }else app("StationService")->locationFreed($stationTaskMaterialBox->station->code); //释放库位占用
  139. DB::commit();
  140. dd("OK");
  141. }catch (\Exception $e){
  142. DB::rollBack();
  143. dd($e->getTrace());
  144. }
  145. }
  146. //快递称重 生成历史数据
  147. public function addRecord(Request $request)
  148. {
  149. ini_set('max_execution_time',-1);
  150. OrderPackageCountingRecord::query()->truncate();
  151. $start = Carbon::parse(request("month"))->startOfMonth();
  152. $end = Carbon::parse(request('month'))->endOfMonth();
  153. foreach (CarbonPeriod::create($start,$end) as $date){
  154. /** @var $date Carbon */
  155. $yesterday = $date->format("Y-m-d");
  156. $sql = <<<sql
  157. SELECT DATE_FORMAT(order_packages.created_at,'%Y-%m-%d') date,IFNULL(order_packages.measuring_machine_id,0) measuring_machine_id,order_packages.owner_id,
  158. SUM(CASE WHEN order_packages.weighed_at IS NOT NULL THEN 1 ELSE 0 END) AS count,
  159. COUNT(1) total FROM order_packages LEFT JOIN orders ON order_packages.order_id=orders.id
  160. WHERE orders.wms_status != '订单取消'
  161. AND order_packages.created_at BETWEEN '{$yesterday} 00:00:00' AND '{$yesterday} 23:59:59' GROUP BY date,order_packages.measuring_machine_id,order_packages.owner_id
  162. sql;
  163. $result = DB::select(DB::raw($sql));
  164. if (!$result) {
  165. $obj = [
  166. "targeted_at" => $yesterday,
  167. "un_weigh_count" => 0,
  168. "total_count" => 0,
  169. "measuring_machine_id" => 0,
  170. "owner_id" => 0
  171. ];
  172. $model = OrderPackageCountingRecord::query()->create($obj);
  173. Cache::put("weight.".$yesterday, $obj);
  174. }else{
  175. $objs = [];
  176. foreach ($result as $v){
  177. $obj = [
  178. "targeted_at" => $v->date,
  179. "un_weigh_count" => $v->count,
  180. "total_count" => $v->total,
  181. "measuring_machine_id" => $v->measuring_machine_id,
  182. "owner_id" => $v->owner_id
  183. ];
  184. $model = OrderPackageCountingRecord::query()->create($obj);
  185. array_push($objs, $obj);
  186. }
  187. Cache::put("weight.".$yesterday, $objs);
  188. }
  189. }
  190. }
  191. public function redis()
  192. {
  193. $start = 1606752000;$end = 1627747200;
  194. $len = ($end - $start) / 86400;
  195. for ($i=0; $i <= $len ; $i ++){
  196. $date = date("Y-m-d", $start + $i * 86400);
  197. Cache::pull('weight.'.$date);
  198. }
  199. }
  200. public function delRedis(Request $request)
  201. {
  202. $date = $request->get('date','');
  203. if (empty($date)) return false;
  204. Cache::pull('weight.'.$date);
  205. }
  206. public function addDateRecords(Request $request)
  207. {
  208. $yesterday = $request->get('date','');
  209. $sql = <<<sql
  210. SELECT DATE_FORMAT(order_packages.created_at,'%Y-%m-%d') date,IFNULL(order_packages.measuring_machine_id,0) measuring_machine_id,order_packages.owner_id,
  211. SUM(CASE WHEN order_packages.weighed_at IS NOT NULL THEN 1 ELSE 0 END) AS count,
  212. COUNT(1) total FROM order_packages LEFT JOIN orders ON order_packages.order_id=orders.id
  213. WHERE orders.wms_status != '订单取消'
  214. AND order_packages.created_at BETWEEN '{$yesterday} 00:00:00' AND '{$yesterday} 23:59:59' GROUP BY date,order_packages.measuring_machine_id,order_packages.owner_id
  215. sql;
  216. $result = DB::select(DB::raw($sql));
  217. if (!$result) {
  218. $obj = [
  219. "targeted_at" => $yesterday,
  220. "un_weigh_count" => 0,
  221. "total_count" => 0,
  222. "measuring_machine_id" => 0,
  223. "owner_id" => 0
  224. ];
  225. $model = OrderPackageCountingRecord::query()->create($obj);
  226. Cache::put("weight.".$yesterday, $obj);
  227. }else{
  228. $objs = [];
  229. foreach ($result as $v){
  230. $obj = [
  231. "targeted_at" => $v->date,
  232. "un_weigh_count" => $v->count,
  233. "total_count" => $v->total,
  234. "measuring_machine_id" => $v->measuring_machine_id,
  235. "owner_id" => $v->owner_id
  236. ];
  237. $model = OrderPackageCountingRecord::query()->create($obj);
  238. array_push($objs, $obj);
  239. }
  240. Cache::put("weight.".$yesterday, $objs);
  241. }
  242. }
  243. public function testZC()
  244. {
  245. $batch=Batch::query()
  246. ->with('orders.orderCommodities.commodity.barcodes')
  247. ->where('code','W210814000158')
  248. ->first();
  249. // dd($batch);
  250. app(ForeignZhenCangService::class)->broadcastBatch($batch);
  251. dd('上传成功');
  252. }
  253. }