Commit ef3e99f7 by duwenjun

删除报价单

parent 007a384f
......@@ -213,6 +213,12 @@ class ApiController extends Controller
Export((new QuoteModel())->cancel($input));
}
// 撤销报价
public function ApiDelQuote($input, $id)
{
Export((new QuoteModel())->del($input));
}
// 新增报价
public function ApiAddQuote($input, $id)
{
......
<?php
/**
* Created by PhpStorm.
* User: duwenjun
* Date: 2021/5/13
* Time: 11:52 AM
*/
namespace App\Http\Utils;
interface AppType
{
const APPTYPE_YUNXIN = 'yunxin'; // 云芯平台
}
\ No newline at end of file
<?php
namespace App\Http\Utils;
class RequestHelper implements AppType
{
public static $client_type = '';
public static $user = null;
public static function setClientType($client_type)
{
self::$client_type = $client_type;
}
public static function getClientType()
{
return self::$client_type;
}
public static function setUser($user)
{
self::$user = $user;
}
public static function getUser()
{
return self::$user;
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
namespace App\Model;
use ClassPreloader\Config;
use App\Http\Utils\RequestHelper;
use Illuminate\Database\Eloquent\Model;
use League\Flysystem\Exception;
use Request;
......@@ -26,7 +26,6 @@ class LoginModel extends Model
if (@$_REQUEST["debug"] == 100){
return ["user_id"=>1000,"user_name"=>"admin"];
}
$Redis= \RedisDB::connection();
//来自不一样的端,判断是否已经登录
$source = $request->header("source"); //来源端:内部后台:pc 云芯系统:yunxin App: app 小程序:h5_app
......@@ -34,15 +33,42 @@ class LoginModel extends Model
if ($token == ""){
Export(1001,"参数 token 不得为空");
}
$userInfoKey = $Redis->keys('frq_login_'.$token."*");
$userInfo = count($userInfoKey) ? $Redis->get($userInfoKey[0]) : "";
if (empty($userInfo)){
Export(1001,"请先登录");
if($source == 'yunxin'){
$cloud_user_info = $this->getCloudSupplierCmsInfo($token);
$userInfo = ['user_id' => $cloud_user_info['userId'], "user_name" => $cloud_user_info['name'], 'email' => $cloud_user_info['email']];
// 设置请求平台类型
RequestHelper::setClientType($source);
// 设置请求用户信息
RequestHelper::setUser($cloud_user_info);
} else {
$Redis= \RedisDB::connection();
$userInfoKey = $Redis->keys('frq_login_'.$token."*");
$userInfo = count($userInfoKey) ? $Redis->get($userInfoKey[0]) : "";
if (empty($userInfo)){
Export(1001,"请先登录");
}
$userInfo = \GuzzleHttp\json_decode($userInfo,true);
}
$userInfo = \GuzzleHttp\json_decode($userInfo,true);
return $userInfo;
}
// 获取云芯用户信息
private function getCloudSupplierCmsInfo($token)
{
$http = new \GuzzleHttp\Client;
$url = Config('website.cloud_domain') . "/api/user/getsupplier.cmsinfo";
$response = $http->get($url, ['query' => ['token'=>$token]]);
$stringBody = (string)$response->getBody();
$res = json_decode($stringBody, true);
if ($res && is_array($res) && ($res['err_code'] === 0)){
return $res['data'];
} else {
Export(1001,"请先登录");
}
}
/*
* 生成token ,目前只有pc端要调用
*/
......@@ -65,7 +91,7 @@ class LoginModel extends Model
public function setLoginCookie($userId, $skey, $header, $expire)
{
setcookie('oa_user_id', $userId, $expire, '/', Config::get('website.cookieDomain'));
setcookie('oa_user_id', $userId, $expire, '/', Config('website.cookieDomain'));
}
/*
......
......@@ -2,6 +2,8 @@
namespace App\Model;
use App\Http\Services\UserService;
use App\Http\Utils\RequestHelper;
use App\map\InquiryMap;
use App\map\OperationLogMap;
use App\map\QuoteMap;
......@@ -31,12 +33,19 @@ class QuoteModel extends Model
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
const STATUS_CANCEL = -1; // 已撤销
const STATUS_OFFER = 1; // 已报价
const STATUS_SELECTED = 2; // 已选中
const STATUS_SURE = 3; // 已确认
const STATUS_CLOSE = 5; // 已关闭
const STATUS_DEL = 9; // 已删除
public function fromDateTime($value)
{
......@@ -137,7 +146,7 @@ class QuoteModel extends Model
$map['start_time'] = !empty($input['start_time']) ? strtotime($input['start_time']) : '';
$map['end_time'] = !empty($input['end_time']) ? strtotime($input['end_time']) + 86399 : '';
// $map = array_filter($map) ? $map : [];
$map = array_filter($map) ? $map : [];
$field = [
'q.id',
'q.inquiry_id',
......@@ -214,7 +223,7 @@ class QuoteModel extends Model
$msg = '成功';
if ($type == 1) { // 我的报价
if ($map['status']) {
if (isset($map['status']) && $map['status']) {
switch($map['status']) {
case 1:
$list['count']['quoted_status'] = $this->commonQuery($map, $input, 2);
......@@ -350,36 +359,39 @@ class QuoteModel extends Model
}
}
$list = $list->where(function ($query) use ($map) {
if ($map['inquiry_sn']) {
$query->where('q.inquiry_sn', '=', $map['inquiry_sn']);
}
$map = array_filter($map);
if ($map){
$list = $list->where(function ($query) use ($map) {
if (isset($map['inquiry_sn']) && $map['inquiry_sn']) {
$query->where('q.inquiry_sn', '=', $map['inquiry_sn']);
}
if ($map['goods_name']) {
$query->where('it.goods_name', 'like', $map['goods_name'] . '%');
}
if (isset($map['goods_name']) && $map['goods_name']) {
$query->where('it.goods_name', 'like', $map['goods_name'] . '%');
}
if ($map['brand_name']) {
$query->where('it.brand_name', 'like', $map['brand_name'] . '%');
}
if (isset($map['brand_name']) && $map['brand_name']) {
$query->where('it.brand_name', 'like', $map['brand_name'] . '%');
}
if ($map['quote_sn']) {
$query->where('q.quote_sn', '=', $map['quote_sn']);
}
if (isset($map['quote_sn']) && $map['quote_sn']) {
$query->where('q.quote_sn', '=', $map['quote_sn']);
}
if ($map['status']) {
$query->where('q.status', '=', $map['status']);
}
if (isset($map['status']) && $map['status']) {
$query->where('q.status', '=', $map['status']);
}
// 创建时间
if(!empty($map['start_time']) && !empty($map['end_time'])) {
$query->whereBetween('q.create_time', [$map['start_time'], $map['end_time']]);
} else if(!empty($map['start_time'])) {
$query->where('q.create_time', '>=', $map['start_time']);
} else if(!empty($map['end_time'])) {
$query->where('q.create_time', '<=', $map['end_time']);
}
});
// 创建时间
if(!empty($map['start_time']) && !empty($map['end_time'])) {
$query->whereBetween('q.create_time', [$map['start_time'], $map['end_time']]);
} else if(!empty($map['start_time'])) {
$query->where('q.create_time', '>=', $map['start_time']);
} else if(!empty($map['end_time'])) {
$query->where('q.create_time', '<=', $map['end_time']);
}
});
}
if ($type == 1) return $list;
......@@ -453,6 +465,51 @@ class QuoteModel extends Model
return [0, '撤销成功'];
}
// 删除报价
public function del($input)
{
$id = $input['id'];
if (!$id) {
return [-1, '参数缺失'];
}
try {
$quote_info = $this->find($id);
if ($quote_info['status'] == self::STATUS_DEL) {
return [1, '删除失败,该报价已删除,请刷新页面查看'];
}
if ($quote_info['status'] !== self::STATUS_OFFER) {
return [1, '删除失败,该报价状态不能删除'];
}
$res = $this->where('id', $id)->update(['status' => self::STATUS_DEL]);
// 查看当前询价明细的报价数量,若为0,则更新询价明细状态为待报价
$count = $this->where('inquiry_items_id', $quote_info['inquiry_items_id'])->whereNotIn('status', [self::STATUS_CANCEL, self::STATUS_CLOSE, self::STATUS_DEL])->count();
$InquiryItemsModel = new InquiryItemsModel;
if (!$count) {
$InquiryItemsModel->where('id', $quote_info['inquiry_items_id'])->update(['status' => 1]);
} else { // 若不为0,且该询价明细状态为‘已选中’,则更新为已报价
$status = $InquiryItemsModel->where('inquiry_items_id',
$quote_info['inquiry_items_id'])->value('status');
if ($status == 3) {
$InquiryItemsModel->where('id', $quote_info['inquiry_items_id'])->update(['status' => 2]);
}
}
// 需要删除当前用户的领取记录
$InquiryItemsAssignModel = new InquiryItemsAssignModel;
$InquiryItemsAssignModel->delAssign($quote_info['inquiry_items_id'], $quote_info['create_uid']);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
return [0, '撤销成功'];
}
/*
* 批量新增报价
*
......
......@@ -23,5 +23,4 @@ class SupplierChannelComModel extends Model
echo json_encode($brandInfo,JSON_UNESCAPED_UNICODE) ;
exit();
}
}
......@@ -10,6 +10,12 @@ class UserModel extends Model
protected $table='user_info';
public $timestamps = false;
public static function getUsersByIds($uids)
{
return self::whereIn('userId', $uids)->select('userId','name','email')->get()->toArray();
}
public function DepartmentUserInfo($Department=''){
if(!$Department) return false;
$OrganizationModel=new OrganizationModel();
......
......@@ -52,6 +52,7 @@ return [
'perm_api' => $domain_config['domain']['perm_api'],
// 获取用户许可权限接口
'check_access_api' => $domain_config['domain']['check_access_api'],
'cloud_domain' => $domain_config['domain']['cloud_domain'],
//上传图片接口地址
'UploadUrl' => $domain_config['upload']['upload_url'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment