小程序供应商报价接口

This commit is contained in:
weiz 2024-05-08 16:42:07 +08:00
parent d21130cbb8
commit 3c8b0c56bb
5 changed files with 117 additions and 5 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace app\api\controller\operation;
use app\api\controller\BaseApiController;
use app\api\lists\operation\OpurchaseGoodsOfferList;
use app\api\logic\operation\OpurchaseGoodsOfferLogic;
use app\api\validate\OpurchaseGoodsOfferValidate;
class OpurchaseGoodsOfferController extends BaseApiController
{
public function list(){
return $this->dataLists(new OpurchaseGoodsOfferList());
}
public function offer(){
// if(!$this->request->userInfo['supplier']) return $this->fail('非供应商用户不能报价');
$params = (new OpurchaseGoodsOfferValidate())->post()->goCheck('offer');
$result = OpurchaseGoodsOfferLogic::offer($params);
if (true === $result) {
return $this->success('报价成功', [], 1, 1);
}
return $this->fail(OpurchaseGoodsOfferLogic::getError());
}
}

View File

@ -38,12 +38,21 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI
*/
public function lists(): array
{
$supplier_id=$this->request->userInfo['supplier']['id'];
$supplier_id=$this->request->userInfo['supplier']['id'] ?? 1;
$params = $this->request->get();
if(isset($params['type']) && $params['type'] == 2){
$where[] = ['price','<>',''];
}else{
$where[] = ['price','=',''];
}
if(!$supplier_id) return [];
return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id)
return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id)->where($where)
->with('goods')
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->select()->each(function($data){
$data['is_adopt_text'] = $data->is_adopt_text;
})
->toArray();
}
@ -55,7 +64,14 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI
*/
public function count(): int
{
return OpurchaseGoodsOffer::where($this->searchWhere)->count();
$supplier_id=$this->request->userInfo['supplier']['id'] ?? 1;
$params = $this->request->get();
if(isset($params['type']) && $params['type'] == 2){
$where[] = ['price','<>',''];
}else{
$where[] = ['price','=',''];
}
return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id)->where($where)->count();
}
}

View File

@ -2,7 +2,28 @@
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['num'],
'update_time' => time()
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace app\api\validate;
use app\common\model\opurchase\OpurchaseGoodsOffer;
use app\common\validate\BaseValidate;
class OpurchaseGoodsOfferValidate extends BaseValidate
{
protected $rule = [
'data' => 'require|checkData',
];
protected $message = [
'data.require' => '参数缺失',
];
public function sceneOffer(): OpurchaseGoodsOfferValidate
{
return $this->only(['data']);
}
public function checkData($value){
if(!is_array($value)) return '参数数据格式错误';
foreach($value as $k => $v){
if(!isset($v['id']) || $v['id'] == ''){
return '第'.($k+1).'行缺少数据主键';
}else{
$data = OpurchaseGoodsOffer::where('id',$v['id'])->where('is_adopt',0)->findOrEmpty();
if($data->isEmpty()) return '第'.($k+1).'行数据信息不存在';
}
if(!isset($v['price']) || $v['price'] == '') {
return '第'.($k+1).'行缺少价格';
}
if(!isset($v['num']) || $v['num'] == '') {
return '第'.($k+1).'行缺少数量';
}
}
return true;
}
}

View File

@ -4,6 +4,7 @@ namespace app\common\model\opurchase;
use app\common\model\BaseModel;
use app\common\model\goods\Goods;
use think\model\concern\SoftDelete;
@ -18,5 +19,13 @@ class OpurchaseGoodsOffer extends BaseModel
protected $deleteTime = 'delete_time';
protected $name = 'OpurchaseGoodsOffer';
public function getIsAdoptTextAttr($value,$data): string
{
return $data['is_adopt'] == 0 ? '未成交' : '已成交';
}
public function goods()
{
return $this->hasOne(Goods::class, 'id', 'goods_id');
}
}