erp/app/api/controller/operation/OpurchaseGoodsOfferController.php

65 lines
2.1 KiB
PHP

<?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;
use app\common\model\goods\Goods;
use app\common\model\goods\Goodsclass;
use think\facade\Db;
class OpurchaseGoodsOfferController extends BaseApiController
{
/**
* 供应商报价列表
*/
public function list()
{
return $this->dataLists(new OpurchaseGoodsOfferList());
}
/**
* @notes 供应商报价日期列表
*/
public function date_lists()
{
if (!$this->request->userInfo['supplier']) return $this->fail('请登录供应商账号');
$supplier=$this->request->userInfo['supplier'];
$page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 15);
$data = Db::name('opurchase_goods_offer_date')->where('supplier_id', $supplier['id'])->page($page_no, $page_size)->select()
->each(function ($item) {
$item['name']=date('Y-m-d', $item['create_time']).' 报价清单';
$item['class_arr']=[];
$goods_id=Db::name('opurchase_goods_offer')->whereDay('create_time',$item['name'])->where('supplier_id', $item['supplier_id'])->limit(3)->column('goods_id');
if($goods_id){
$class=Goods::where('id','in',$goods_id)->column('class');
if($class){
$name=Goodsclass::where('id','in',$class)->column('name');
$item['class_arr']=$name;
}
}
return $item;
})->toArray();
$count = Db::name('opurchase_goods_offer_date')->where('supplier_id', $supplier['id'])->count();
return $this->success('请求成功', ['lists' => $data, 'count' => $count, 'page_no' => $page_no, 'page_size' => $page_size]);
}
/**
* 提交报价
*/
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());
}
}