erp/app/api/logic/operation/OpurchaseGoodsOfferLogic.php

73 lines
1.8 KiB
PHP

<?php
namespace app\api\logic\operation;
use app\common\logic\BaseLogic;
use app\common\model\opurchase\OpurchaseGoodsOffer;
use think\facade\Db;
class OpurchaseGoodsOfferLogic extends BaseLogic
{
public static function offer($params): bool
{
Db::startTrans();
try {
foreach ($params['data'] as $v) {
OpurchaseGoodsOffer::where('id', $v['id'])->update([
'price' => $v['price'],
'nums' => $v['nums'],
'is_adopt' => 1,
'update_time' => time()
]);
}
$id = $params['data'][0]['id'] ?? 0;
if ($id) {
$find = OpurchaseGoodsOffer::where('id', $params['data'][0]['id'])->field('supplier_id', 'create_time')->find();
if ($find) {
$time = date('Y-m-d', $find['create_time']);
Db::name('opurchase_goods_offer_date')->where('supplier_id', $find['supplier_id'])->whereDay('create_time', $time)->update(['status' => 1]);
}
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* 更新配送
*/
public static function express($params): bool
{
Db::startTrans();
try {
$where=['supplier_id'=>$params['supplier_id']];
if(isset($params['id']) &&$params['id']!=[]){
$where[]=['id','in',$params['id']];
}
if(isset($params['date']) &&$params['date']!=''){
$time=strtotime($params['date']);
$where[]=['create_time','between',[$time,$time+24*60*60-1]];//当天时间范围
}
$where['is_adopt']=2;
OpurchaseGoodsOffer::where($where)->update([
'delivery_name' => $params['delivery_name'],
'delivery_id' => $params['delivery_id'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}