|
@@ -448,7 +448,11 @@ class Purch extends Base
|
|
|
if($cg==""){
|
|
|
return error_show(1002,"未找到采购单数据");
|
|
|
}
|
|
|
- $gd= Db::name('good')->where(['spuCode'=>$cg['spuCode']])->find();
|
|
|
+ if($cg['order_type']==3|| $cg['order_type']==4){
|
|
|
+ $gd = Db::name("good_zixun")->where(["spuCode"=>$cg['spuCode']])->find();
|
|
|
+ }else {
|
|
|
+ $gd =Db::name('good_basic')->where(['spuCode'=>$cg['spuCode']])->find();
|
|
|
+ }
|
|
|
if($gd==""){
|
|
|
return error_show(1002,"未找到商品数据");
|
|
|
}
|
|
@@ -462,13 +466,13 @@ class Purch extends Base
|
|
|
}
|
|
|
$rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
|
|
|
$rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
|
|
|
- $diff_price = $diff_weight*$cg['gold_price'];
|
|
|
+ $diff_price = round($diff_weight*$cg['gold_price']+$diff_weight*$cg['teach_fee'],2);
|
|
|
$data=[
|
|
|
"cgdNo"=>$cgdNo,
|
|
|
"good_code"=>$cg['spuCode'],
|
|
|
"good_name"=>$cg['good_name'],
|
|
|
"sale_price"=>$cg['good_price'],
|
|
|
- "good_weight"=>$cg['weight'],
|
|
|
+ "good_weight"=>$cg['weight']*$cg['good_num'],
|
|
|
"good_num"=>$cg['good_num'],
|
|
|
"apply_id"=>$rid,
|
|
|
"apply_name"=>$rname,
|
|
@@ -484,27 +488,22 @@ class Purch extends Base
|
|
|
try{
|
|
|
$item = Db::name("purchease_diff")->insert($data,true);
|
|
|
if($item>0){
|
|
|
-// $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
|
|
|
-// ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
|
|
|
-// $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
|
|
|
-// ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
- $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->column("orderCode");
|
|
|
-
|
|
|
- if(!empty($orderCode)){
|
|
|
- $order = Db::name("sale")->where("orderCode", 'in', $orderCode)->select()->toArray();
|
|
|
- if(empty($order)){
|
|
|
+ $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->find();
|
|
|
+ if($orderCode!=false){
|
|
|
+ $order = Db::name("sale")->where("orderCode", '=', $orderCode['orderCode'])->find();
|
|
|
+ if($order==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"未找到确认单信息");
|
|
|
}
|
|
|
- foreach ($orderCode as $value){
|
|
|
+
|
|
|
$data=[
|
|
|
"cgd_diffid"=>$item,
|
|
|
- "orderCode"=>$value,
|
|
|
+ "orderCode"=>$orderCode['orderCode'],
|
|
|
"good_code"=>$cg['spuCode'],
|
|
|
"good_name"=>$cg['good_name'],
|
|
|
"diff_weight"=>$diff_weight,
|
|
|
- "diff_price"=>$diff_weight*$cg['good_price'],
|
|
|
- "gold_price"=>$cg['good_price'],
|
|
|
+ "diff_price"=>round($diff_weight*$order['gold_price']+$diff_weight*$order['cost_price'],2),
|
|
|
+ "gold_price"=>$order['sale_price'],
|
|
|
"status"=>1,
|
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
@@ -520,7 +519,7 @@ class Purch extends Base
|
|
|
// }else{
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"新建失败");
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -634,29 +633,60 @@ class Purch extends Base
|
|
|
}
|
|
|
$dio = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
if(empty($dio)){
|
|
|
- return error_show(1002,"退货订单未找到");
|
|
|
+ return error_show(1002,"工差订单未找到");
|
|
|
}
|
|
|
$cgd = Db::name("purchease_order")->where(['cgdNo'=>$dio['cgdNo']])->find();
|
|
|
if(empty($cgd)){
|
|
|
return error_show(1002,"采购单未找到");
|
|
|
}
|
|
|
+ $salediff=Db::name("sale_diff")->where(["cgd_diffid"=>$dio['id']])->find();
|
|
|
+ if($salediff==false){
|
|
|
+ return error_show(1002,"销售工差单未找到");
|
|
|
+ }
|
|
|
$status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
|
|
|
if($status===""){
|
|
|
return error_show(1002,"参数status不能为空");
|
|
|
}
|
|
|
- $temp = $dio['status'];
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $temp = $dio['status'];
|
|
|
$dio['status']=$status;
|
|
|
$dio['updatetime']=date("Y-m-d H:i:s");
|
|
|
$item = Db::name("purchease_diff")->save($dio);
|
|
|
- if ($item){
|
|
|
-// $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
|
|
|
-// ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
|
|
|
-// $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
|
|
|
-// ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
+ if ($item){
|
|
|
+ if($status==2){
|
|
|
+ $cgd['diff_fee'] =$dio['diff_price'];
|
|
|
+ $cgd['diff_weight'] =$dio['diff_weight'];
|
|
|
+ $cgd['updatetime'] =date("Y-m-d H:i:s");
|
|
|
+ $cgp=Db::name("purchease_order")->save($cgd);
|
|
|
+ if($cgp==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"采购单更新失败");
|
|
|
+ }
|
|
|
+ if($salediff['is_act']==1){
|
|
|
+ $saled=[
|
|
|
+ "diff_fee"=>$salediff['diff_price'],
|
|
|
+ "diff_weight"=>$salediff['diff_weight'],
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $up =Db::name("sale")->where(["orderCode"=>$salediff['orderCode']])->save($saled);
|
|
|
+ if($up==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"销售单更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
return error_show(0,"更新成功");
|
|
|
}else{
|
|
|
+ Db::rollback();
|
|
|
return error_show(1002,"更新失败");
|
|
|
}
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,$e->getMessage()."|".$e->getLine());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -672,16 +702,21 @@ class Purch extends Base
|
|
|
|
|
|
//采购单
|
|
|
$data = Db::name("purchease_order")
|
|
|
- ->field('id,status')
|
|
|
+ ->field('id,demo_fee,good_num,weight,open_fee,teach_fee,pakge_fee,mark_fee,cert_fee,nake_fee,delivery_fee,status')
|
|
|
->where(["cgdNo" => $param['cgdNo'], "is_del" => 0])
|
|
|
->find();
|
|
|
|
|
|
if (empty($data)) return error_show(1004, "未找到该采购单数据");
|
|
|
if ($data['status'] != 0) return error_show(1005, '该状态下不允许修改实时金价');
|
|
|
+ $sale_price = round($data['demo_fee'] / $data['good_num'] + $data['open_fee'] / $data['good_num'] +
|
|
|
+ $data['weight'] * $param["gold_price"] + $data['teach_fee'] * $data['weight'] +
|
|
|
+ $data['pakge_fee'] + $data['mark_fee'] + $data['cert_fee'] +$data['nake_fee'] + $data['delivery_fee'],2);
|
|
|
+ $total_price = round($data['good_num']*$sale_price,2);
|
|
|
|
|
|
$rs = Db::name("purchease_order")
|
|
|
->where('id', $data['id'])
|
|
|
- ->update(['updatetime' => date('Y-m-d H:i:s'), 'gold_price' => $param['gold_price']]);
|
|
|
+ ->update(['updatetime' => date('Y-m-d H:i:s'), 'gold_price' => $param['gold_price'],
|
|
|
+ "good_price"=>$sale_price,"total_fee"=>$total_price]);
|
|
|
|
|
|
return $rs ? app_show(0, '修改采购单实时金价成功') : error_show(1005, '修改采购单实时金价失败');
|
|
|
|