dataLists(new WarehouseOrderLists()); } /** * @notes 添加入库单 * @return \think\response\Json * @author admin * @date 2024/08/20 10:50 */ public function add() { $params = $this->request->post(); $params['admin_id'] = $this->adminId; $result = WarehouseOrderLogic::add($params); if (true === $result) { return $this->success('添加成功', [], 1, 1); } return $this->fail(WarehouseOrderLogic::getError()); } /** * @notes 添加出库单 * @return \think\response\Json * @author admin * @date 2024/08/20 10:50 */ public function outbound() { $product_arr = $this->request->post('product_arr'); $store_arr = $this->request->post('store_arr'); $warehouse_id = $this->request->post('warehouse_id'); $delivery_time = $this->request->post('delivery_time'); $mark = $this->request->post('mark'); $count = count($store_arr); // foreach ($product_arr as $key => $arr) { // $stock = bcmul($arr['stock'], $count); // $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums'); // if ($nums < $stock) { // return $this->fail('商品库存不足'); // } // } Db::startTrans(); try { if ($count == 1) { $store_id = $store_arr[0]; $arr = [ 'warehouse_id' => $warehouse_id, 'store_id' => $store_id, 'supplier_id' => 0, 'code' => getNewOrderId('PS'), 'admin_id' => $this->adminId, 'financial_pm' => 0, 'batch' => 0, 'mark' => $mark ?? "", ]; $arr['delivery_time'] = strtotime($delivery_time); $res = WarehouseOrder::create($arr); foreach ($product_arr as $key => $arr) { $data = [ 'warehouse_id' => $warehouse_id, 'product_id' => $arr['id'], 'store_id' => $store_id, 'financial_pm' => 0, 'batch' => 1, 'nums' => $arr['stock'], 'status' => 1, 'admin_id' => $this->adminId, ]; $storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); if ($arr['stock'] == 0) { StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct); } else { $data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2); $data['purchase'] = $storeProduct['purchase']; $data['oid'] = $res['id']; WarehouseProductLogic::add($data); $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); } } } Db::commit(); } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1); } /** * @notes 编辑仓储商品单 * @return \think\response\Json * @author admin * @date 2024/08/20 10:50 */ public function edit() { $params = $this->request->post(); $params['admin_id']=$this->adminId; $result = WarehouseOrderLogic::edit($params); if (true === $result) { return $this->success('编辑成功', [], 1, 1); } return $this->fail(WarehouseOrderLogic::getError()); } /** * @notes 删除仓储商品单 * @return \think\response\Json * @author admin * @date 2024/08/20 10:50 */ public function delete() { $params = (new WarehouseOrderValidate())->post()->goCheck('delete'); WarehouseOrderLogic::delete($params); if(WarehouseOrderLogic::hasError()){ return $this->fail(WarehouseOrderLogic::getError()); } return $this->success('删除成功', [], 1, 1); } /** * @notes 获取仓储商品单详情 * @return \think\response\Json * @author admin * @date 2024/08/20 10:50 */ public function detail() { $params = (new WarehouseOrderValidate())->goCheck('detail'); $result = WarehouseOrderLogic::detail($params); return $this->data($result); } /** * 入库表格 */ public function rentry_export() { $id = $this->request->post('id'); $xlsx = new WarehouseOrdeRentry(); $order = WarehouseOrder::where('id', $id)->findOrEmpty(); $data = WarehouseProduct::where('oid', $id)->select(); $order['total_num'] = 0; foreach ($data as $key => &$value) { $find = StoreProduct::where('id', $value->product_id)->find(); $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; if (!empty($find['unit'])) { $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); } else { $value->unit_name = ''; } $order['total_num'] += $value->nums; } $file_path = $xlsx->export($data, $order); return $this->success('导出成功', ['url' => $file_path]); } /** * 出库表格 */ public function export() { $id = $this->request->post('id'); $type = $this->request->post('type'); $xlsx = new OrderDetail(); $order = WarehouseOrder::where('id', $id)->findOrEmpty(); $system_store = SystemStore::where('id', $order['store_id'])->value('name'); $data = WarehouseProduct::where('oid', $id)->select(); $order['total_num'] = 0; $total_price=0; foreach ($data as $key => &$value) { $find = StoreProduct::where('id', $value->product_id)->find(); $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; if($type==2){ $value->price = $find['price']; $value->total_price=bcmul($find['price'],$value['nums'],2); $total_price+=$value->total_price; }else{ $value->price = $value['purchase']; } $value->cart_num = $value['nums']; if (!empty($find['unit'])) { $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); } else { $value->unit_name = ''; } $order['total_num'] += $value->nums; } if($type==2){ $order['total_price']=$total_price; } $order['delivery_time']=date('Y-m-d H:i:s',$order['delivery_time']); $order['pay_time']=$order['create_time']; $order['order_id']=$order['code']; $file_path = $xlsx->export($data, $system_store, $order); return $this->success('导出成功', ['url' => $file_path]); } }