1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\model;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class CgdPrice extends Model
- {
- protected $createTime="addtime";
- protected $updateTime="updatetime";
- /**修改成本单价
- * @param $orderInfo
- * @return array
- */
- public static function checkCgdPrice($orderInfo){
- $totalPrice='0';
- $temp = self::checkCgdNum($orderInfo,$totalPrice);
- $orderInfo->origin_price = bcdiv($totalPrice,$orderInfo->good_num,6);
- Sale::save($orderInfo->toArray());
- return $temp;
- }
- /**修改成本数量
- * @param $orderInfo
- * @param string $totalPrice
- * @return array
- * @throws \think\Exception
- */
- public static function checkCgdNum($orderInfo,&$totalPrice="0"){
- $temp=[];
- $num = $orderInfo->good_num;
- $totalPrice='0';
- while ($num>0){
- $item =self::where([['goodNo','=',$orderInfo->good_code],['status','=',1]])->findOrEmpty();
- if($item->isEmpty()){
- $tempNum = $num;
- $num=0;
- }else{
- $balance = $item->goodNum-$item->usedNum;
- if($num>=$balance){
- $tempNum = $balance;
- $num-=$balance;
- }else{
- $tempNum = $num;
- $num=0;
- }
- self::where($item->toArray())->save(['usedNum'=>$item->usedNum+$tempNum,'status'=>$item->usedNum+$tempNum>=$item->goodNum?2:1]);
- }
-
- $tep=[
- 'orderCode'=>$orderInfo->orderCode,
- 'cgd_price_id'=>$item->id??0,
- 'num'=>$tempNum,
- 'goodPrice'=>$item->goodPrice??0,
- ];
- $totalPrice =bcadd(bcmul($item->goodPrice,strval($tempNum),6),$totalPrice,6);
- $temp[]=$tep;
- }
- return $temp;
- }
-
- public static function checkCgdPriceLow($orderInfo,$num){
-
- }
- }
|