CgdPrice.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\model;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class CgdPrice extends Model
  9. {
  10. protected $createTime="addtime";
  11. protected $updateTime="updatetime";
  12. /**修改成本单价
  13. * @param $orderInfo
  14. * @return array
  15. */
  16. public static function checkCgdPrice($orderInfo){
  17. $totalPrice='0';
  18. $temp = self::checkCgdNum($orderInfo,$totalPrice);
  19. $orderInfo->origin_price = bcdiv($totalPrice,$orderInfo->good_num,6);
  20. Sale::save($orderInfo->toArray());
  21. return $temp;
  22. }
  23. /**修改成本数量
  24. * @param $orderInfo
  25. * @param string $totalPrice
  26. * @return array
  27. * @throws \think\Exception
  28. */
  29. public static function checkCgdNum($orderInfo,&$totalPrice="0"){
  30. $temp=[];
  31. $num = $orderInfo->good_num;
  32. $totalPrice='0';
  33. while ($num>0){
  34. $item =self::where([['goodNo','=',$orderInfo->good_code],['status','=',1]])->findOrEmpty();
  35. if($item->isEmpty()){
  36. $tempNum = $num;
  37. $num=0;
  38. }else{
  39. $balance = $item->goodNum-$item->usedNum;
  40. if($num>=$balance){
  41. $tempNum = $balance;
  42. $num-=$balance;
  43. }else{
  44. $tempNum = $num;
  45. $num=0;
  46. }
  47. self::where($item->toArray())->save(['usedNum'=>$item->usedNum+$tempNum,'status'=>$item->usedNum+$tempNum>=$item->goodNum?2:1]);
  48. }
  49. $tep=[
  50. 'orderCode'=>$orderInfo->orderCode,
  51. 'cgd_price_id'=>$item->id??0,
  52. 'num'=>$tempNum,
  53. 'goodPrice'=>$item->goodPrice??0,
  54. ];
  55. $totalPrice =bcadd(bcmul($item->goodPrice,strval($tempNum),6),$totalPrice,6);
  56. $temp[]=$tep;
  57. }
  58. return $temp;
  59. }
  60. public static function checkCgdPriceLow($orderInfo,$num){
  61. }
  62. }