diff --git a/app/admin/logic/operation/OpurchaseclassLogic.php b/app/admin/logic/operation/OpurchaseclassLogic.php index 79c7a4c..875fa03 100644 --- a/app/admin/logic/operation/OpurchaseclassLogic.php +++ b/app/admin/logic/operation/OpurchaseclassLogic.php @@ -2,9 +2,10 @@ namespace app\admin\logic\operation; - +use app\common\enum\OrderEnum; use app\common\model\operation\Opurchaseclass; use app\common\logic\BaseLogic; +use app\common\model\financial\FinancialRecord; use app\common\model\goods\Goods; use app\common\model\merchant\Merchant; use app\common\model\opurchase\OpurchaseGoodsOffer; @@ -64,7 +65,7 @@ class OpurchaseclassLogic extends BaseLogic } $order = [ 'time' => time(), - 'number' => static::getNewOrderId('CG'), + 'number' => getNewOrderId('CG'), 'total' => array_sum(array_column($cart_select, 'total')), 'pay_type' => $params['pay_type'] ?? 0, 'cart_id' => implode(',', $cart_arr), @@ -196,10 +197,10 @@ class OpurchaseclassLogic extends BaseLogic public static function createSupplierGoods($goods) { try { - $supplier_arr = SupplierBindGoods::where('goods_id',$goods['goods'])->column('supplier_id'); + $supplier_arr = SupplierBindGoods::where('goods_id', $goods['goods'])->column('supplier_id'); if ($supplier_arr) { $supplier_arr = array_unique($supplier_arr); - $time=strtotime(date('Y-m-d',time())); + $time = strtotime(date('Y-m-d', time())); foreach ($supplier_arr as $k => $v) { $goods_offer[] = [ 'supplier_id' => $v, @@ -209,11 +210,11 @@ class OpurchaseclassLogic extends BaseLogic 'need_num' => $goods['nums'], 'create_time' => time() ]; - $find=Db::name('opurchase_goods_offer_date')->where('supplier_id',$v)->where('create_time',$time)->find(); - if($find){ - Db::name('opurchase_goods_offer_date')->where('id',$find['id'])->inc('nums')->update(); - }else{ - $data=['supplier_id'=>$v,'nums'=>1,'create_time'=>$time]; + $find = Db::name('opurchase_goods_offer_date')->where('supplier_id', $v)->where('create_time', $time)->find(); + if ($find) { + Db::name('opurchase_goods_offer_date')->where('id', $find['id'])->inc('nums')->update(); + } else { + $data = ['supplier_id' => $v, 'nums' => 1, 'create_time' => $time]; Db::name('opurchase_goods_offer_date')->insert($data); } } @@ -253,6 +254,40 @@ class OpurchaseclassLogic extends BaseLogic $find->notes = $notes; $find->before_nums = $find->nums; $find->nums = $nums; + $price=0; + if ($nums != 0) { + $price = bcmul($find['price'], $nums, 2); + Supplier::where('id', $id)->inc('mer_money', $price)->update(); + } + $number=Opurchaseclass::where('id',$find['order_id'])->value('number'); + $time=time(); + //平台支出 + $record[] = [ + 'financial_record_sn' => $time, + 'order_id' => $find['order_id'], + 'number_sn' => $number, + 'user_id' => 0, + 'financial_type' => OrderEnum::PLATFORM_ORDER_PAY, + 'financial_pm' => OrderEnum::EXPENDITURE, + 'number' => $price, + 'status' => 1, + 'type' => OrderEnum::USER, + 'mer_id' => getenv('OPERATED') + ]; + //供应链获得流水 + $record[] = [ + 'financial_record_sn' => $time, + 'order_id' => $find['order_id'], + 'number_sn' => $number, + 'user_id' => 0, + 'financial_type' => OrderEnum::PLATFORM_ORDER_OBTAINS, + 'financial_pm' => OrderEnum::INCOME, + 'number' => $price, + 'status' => 1, + 'type' => OrderEnum::SUPPLIER, + 'mer_id' => $find['supplier_id'], + ]; + (new FinancialRecord())->saveAll($record); } $res = $find->save(); if ($res) { @@ -264,19 +299,4 @@ class OpurchaseclassLogic extends BaseLogic return false; } } - - /** - * @notes 获取订单号 - * @param $type - * @return string - * @author likeadmin - * @date 2021/7/28 17:05 - */ - static public function getNewOrderId($type) - { - list($msec, $sec) = explode(' ', microtime()); - $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); - $orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369)); - return $orderId; - } }