123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace App\Listeners;
- use App\Events\RetailOutboundEvent;
- use App\Models\ExpressStorage;
- use App\Models\OrderDetailW;
- use App\Models\UserStorage;
- use App\Models\User;
- use App\Models\Store;
- use App\Models\OrderW;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Queue\InteractsWithQueue;
- class RetailOutboundListener
- {
- /**
- * @param ExampleEvent $event
- * @return void
- */
- public function handle(RetailOutboundEvent $event)
- {
- Log::info('111111111123');
- Log::error('//'.json_encode($event));
- $order_no=$event->data;
- $order=OrderW::where('order_no',$order_no)->first();
- $user_id=Store::where('id',$order->store_id)->value('user_id');
- $user=User::find($user_id);
- Log::error('//'.json_encode($order_no));
- if($user->level==3){
- $order_goods=OrderDetailW::with('goods')->where('order_no',$order_no)->get();
- foreach($order_goods as $key=>$val){
- $goods=$val->goods;
- Log::info('!!!@@@'.$goods->main_attr);
- $type=$this->type($goods->main_attr);
- $sex=$this->sex($val->type);
- $size=$this->size($val->size);
- $num=(int)$val->num;
- $data=UserStorage::where('user_id',$user_id)->where('type',$type)
- ->where('sex',$sex)->where('size',$size)->lockForUpdate()->first();
- if($data){
- $data->num -= $num;
- $data->save();
- }else{
- UserStorage::create([
- 'user_id'=> $user_id,
- 'type' => $type,
- 'sex' => $sex,
- 'size' => $size,
- 'num' => -$num,
- ]);
- }
- ExpressStorage::create([
- 'user_id'=>$user_id,
- 'size'=>$size,
- 'sex'=>$sex,
- 'type'=>$type,
- 'num'=>$num,
- 'storage_type'=>1,
- 'out_time'=>date("Y-m-d H:i:s"),
- 'out_type'=>0,
- 'order_no'=>$order_no,
- 'remark'=>'零售减库存'
- ]);
- }
- }
- }
- function type($attr_main){
- switch($attr_main){
- case '精装版':
- return 0;
- break;
- case '简约版':
- return 1;
- break;
- case '老人版':
- case '高腰版':
- return 2;
- break;
- case '纯棉老人版':
- return 3;
- break;
- case '青春版':
- return 4;
- break;
- default:
- return 9;
- }
- }
- function sex($sex){
- if($sex=='女款'){
- return 0;
- }
- return 1;
- }
- function size($size){
- $size=strtoupper($size);
- if($size=='XXL'){
- return '2XL';
- }
- if($size=='XXXL'){
- return '3XL';
- }
- if($size=='XXXXL'){
- return '4XL';
- }
- if($size=='XXXXXL'){
- return '5XL';
- }
- return $size;
- }
- }
|