TestController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Components\ErrorPush;
  5. use App\ErrorTemp;
  6. use App\Feature;
  7. use App\Owner;
  8. use App\OwnerFeeDetail;
  9. use App\OwnerPriceOperation;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Http;
  13. class TestController extends Controller
  14. {
  15. use AsyncResponse,ErrorPush;
  16. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  17. private $data = [];
  18. public function __construct()
  19. {
  20. $this->data["active_test"] = "active";
  21. }
  22. public function method(Request $request, $method)
  23. {
  24. return call_user_func([$this, $method], $request);
  25. }
  26. public function lightUp()
  27. {
  28. app("CacheShelfService")->lightUp('HAIB1-02-02','3','2');
  29. }
  30. public function lightOff()
  31. {
  32. $params = [
  33. "areaCode" => "1004",
  34. 'locCode' => "HAIB1-02-02",
  35. 'PTLAction' => 0,
  36. ];
  37. $response = Http::post(config('api.haiq.storage.light'), $params);
  38. return json_decode($response->body());
  39. }
  40. public function test()
  41. {
  42. ini_set('max_execution_time',-1);
  43. $rule = OwnerPriceOperation::query()->with("items")->find(205);
  44. $owner = 3;$discountIndex = 0;
  45. $pivot = new \stdClass();
  46. $pivot->owner_price_operation_id = 205;
  47. $pivot->owner_id = 3;
  48. $pivot->discount_date = "2021-08-01";
  49. $pivot->target_value = 0;
  50. DB::beginTransaction();
  51. try{
  52. $month = date("Y-m");
  53. $day = date("t",strtotime($month));
  54. $query = OwnerFeeDetail::query()->where("owner_id",$owner)->whereBetween("worked_at",[$month."-01",$month."-".$day]);
  55. $units = app("UnitService")->getUnitMapping(["件","单","箱","m³","T","kg"]); //获取单位映射集
  56. $exe = function ($mapping,$object,$detail)use($rule,$units,$owner,$discountIndex){
  57. $money = app("OwnerPriceOperationService")->matchItem($rule,$mapping,$object,$units,$owner,[$discountIndex=>true]);
  58. $rate = $rule->taxRate ?: (Owner::query()->with("taxRate")->find($owner)->taxRate ?? null);
  59. if ($money>0)$detail->update(["work_fee"=>$money,"work_tax_fee"=>$rate ? ($money*($rate->value/100)) : null]);
  60. else dd($money);
  61. };
  62. if ($rule->operation_type=='入库'){
  63. foreach ($query->with(["store.storeItems.commodity","store.warehouse"])
  64. ->where("outer_table_name",'stores')->get() as $detail)
  65. $exe(Feature::MAPPING["store"],$detail->store,$detail);
  66. }else{
  67. foreach ($query->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
  68. ->where("outer_table_name",'orders')->get() as $detail)
  69. $exe(Feature::MAPPING["order"],$detail->order,$detail);
  70. }
  71. DB::commit();
  72. dd("OK");
  73. }catch (\Exception $e){
  74. DB::rollBack();
  75. //处理失败回退标记
  76. DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE owner_price_operation_id = ? AND owner_id = ?"),
  77. [$pivot->discount_date,$pivot->target_value,$rule->id,$owner]);
  78. dd($e);
  79. }
  80. }
  81. }