45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\purchase_order_info;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\purchase_order_info\PurchaseOrderInfo;
|
|
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use support\exception\BusinessException;
|
|
use think\facade\Db;
|
|
|
|
class PurchaseOrderInfoLogic extends BaseLogic
|
|
{
|
|
/**
|
|
* 是否需采购
|
|
*/
|
|
public static function buyer($params)
|
|
{
|
|
$data['is_buyer'] = $params['is_buyer'];
|
|
Db::startTrans();
|
|
try {
|
|
if ($params['is_buyer'] == 1&& $params['poid']>0) {
|
|
$data['buyer_nums'] = $params['buyer_nums'];
|
|
$find = PurchaseProductOffer::where('order_id', $params['poid'])->where('product_id', $params['product_id'])->find();
|
|
if ($find) {
|
|
PurchaseProductOffer::where('id', $find['id'])->inc('buyer_nums', $params['buyer_nums'])->update();
|
|
} else {
|
|
$arr['order_id'] = $params['poid'];
|
|
$arr['product_id'] = $params['product_id'];
|
|
$arr['need_num'] = $params['cart_num'];
|
|
$arr['buyer_nums'] = $params['buyer_nums'];
|
|
$arr['unit'] = StoreProduct::where('id', $params['product_id'])->value('unit');
|
|
PurchaseProductOffer::create($arr);
|
|
}
|
|
}
|
|
PurchaseOrderInfo::where('id', $params['id'])->update($data);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
}
|