findOrEmpty()->toArray(); $store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); if ($find && !$store_find) { $attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty(); Db::startTrans(); try { $product = [ 'product_id' => $find['id'], 'image' => $find['image'], 'store_name' => $find['store_name'], 'store_info' => $find['store_info'], 'keyword' => $find['keyword'], 'bar_code' => $find['bar_code'], 'cate_id' => $find['cate_id'], 'price' => $find['price'], 'unit' => $find['unit'], 'store_id' => $store_id, 'sales' => 0, 'stock' => 0, ]; $branch=StoreBranchProduct::create($product); $arr = [ 'product_id' => $product_arr['id'], 'store_id' => $store_id, 'unique' => setUnique($branch['id'], '', 0), 'sales' => 0, 'type' => 0, 'bar_code' => $attr_value['bar_code'] ]; StoreBranchProductAttrValue::create($arr); $this->storage($find, $store_id, $admin_id, $product_arr); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile()); return false; } } else { Db::startTrans(); try { $this->storage($find, $store_id, $admin_id, $product_arr); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); Log::error('store-storage队列消费失败: ' . $e->getMessage().',line:'.$e->getLine().',file:'.$e->getFile()); return false; } } } public function storage($find, $store_id, $admin_id, $product_arr) { $storage = [ 'product_id' => $product_arr['id'], 'store_id' => $store_id, 'nums' => $product_arr['stock'], 'admin_id' => $admin_id, ]; if ($find['stock'] < $product_arr['stock']) { $storage['status'] = -1; $storage['mark'] = '库存不足,主库存为:' . $find['stock']; SystemStoreStorage::create($storage); }else{ SystemStoreStorage::create($storage); StoreProduct::where('id', $product_arr['id'])->dec('stock',$product_arr['stock'])->update(); } } public function onConsumeFailure(\Throwable $e, $package) { $package['max_attempts'] = 0; return $package; } }