🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### 订单录入SKU发货数量的编辑 **位置:** Common\Lib\FlowLib.class.php **参数:** * @param $data array 订单信息(如:订单类型,订单ID) * @return array 订单审批返回提示信息 **调用:** * $flow = new FlowLib(); * $order_arr = $flow->skuEdit($data); **完整代码:** ~~~ /** * 订单录入SKU发货数量的编辑 * @param $data array 订单信息 * @return int 编辑是否成功返回 * whz 2018-01-26 * */ public function skuEdit($data) { //1、检查发货数量不能小于0 if ((int)$data['num'] <= 0) { return array('success'=>false, 'code'=>202, 'msg'=>'填写SKU数量必须大于0!'); } //2、查询SKU库存信息 if ($data['order_type'] == 1 || $data['order_type'] == 4) { //查询仓库名 $delivery = get_warehouse($data['shipper_id']); $where['warehouse'] = $data['shipper_id']; //配货、移库的商品必须在仓库(物流状态:1、已入库) $where['delivery_status'] = 1; } //订单类型:调拨单、退仓单,发货位置是门店 if ($data['order_type'] == 2 || $data['order_type'] == 3) { //查询门店名 $delivery = get_shops_name($data['shipper_id']); $where['max_shops_id'] = $data['shipper_id']; //调拨、退仓的商品必须在门店(2、已入店) $where['delivery_status'] = 2; } //相同SKU的商品sku_id相同 $where['sku_id'] = $data['sku_id']; //可销售 $where['inventory_status'] = array('in',array(1,2,3,5,6)); //SKU在唯一码表找到商品的个数 $goodcount = M('goods_no') ->where($where) ->count(); if ($goodcount == 0) { return array('success'=>false, 'code'=>203, 'msg'=>$delivery . '可填数量为:0'); } //3、判断编辑的发货数量是否正确 $num_sku = M('wms_flow as r') ->field('u.num') ->join('coscia_wms_sku as u on r.id=u.order_id','left') ->where(array('u.type'=>$data['order_type'], 'u.sku_id'=>$data['sku_id'], 'u.is_delete'=>0, 'r.status'=>array('in',array(0,1,2)), 'r.id'=>array('neq',$data['id']))) ->select(); $num_skus = 0; foreach ($num_sku as $key => $value) { $num_skus += $value['num']; } $nums = $goodcount-$num_skus; if ((int)$data['num'] > (int)$nums) { return array('success'=>false, 'code'=>204, 'msg'=>'SKU:' . $data['sku'] . '库存不足,可发库存:' . $goodcount . ',减去已录入SKU订单的发货数量:' . $num_skus . '后,库存量为:' . $nums); } M()->startTrans(); //6、更新配货数量 $save_num = M("wms_sku") ->where(array('id' => $data['save_id'])) ->save(array('num' => $data['num'])); if ($save_num === false) { M()->rollback(); return array('success'=>false, 'code'=>205, 'msg'=>'SKU数量更新失败!'); } //7、生成日志记录 $add_log['description'] = $data['sku'].'修改SKU数量为:'.$data['num'].'成功!'; $add_log['order_id'] = $data['id']; $add_log['type'] = $data['order_type']; $ress = $this->addLog($add_log); if (!$ress) { M()->rollback(); return array('success'=>false, 'code'=>208, 'msg'=>'修改SKU数量日志记录失败!'); } M()->commit(); return array('success'=>true, 'code'=>200, 'msg'=>'修改成功!'); } ~~~