TestController.php 8.7 KB

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