<?php
|
|
namespace app\admin\controller;
|
|
use think\Exception;
|
use think\facade\Db;
|
use think\facade\View;
|
use think\facade\Request;
|
use app\supplier\validate\LogisticsProduct;
|
|
class ThirdPartyLogisticsProductTemp extends Common {
|
|
/**
|
* 新建物流产品首页
|
* @return string
|
*/
|
public function index() {
|
////////
|
return View::fetch();
|
}
|
|
/**
|
* 审核物流产品
|
* @return array|int[]
|
*/
|
public function reviewLogisticsProduct() {
|
// 开始数据库事务
|
Db::startTrans();
|
try {
|
if (!Request::isPost()) {
|
throw new Exception(lang('request_method_incorrect'));
|
}
|
$id = input('post.id');
|
if (is_numeric($id)) {
|
$status = input('post.status');
|
//更新数据
|
$info = Db::name('logistics_product')->field('id,status')->where('id', $id)->find();
|
if (!$info) {
|
return $this->errorResponse(lang('request_method_incorrect'));
|
}
|
if ($status == 1) {
|
Db::name('logistics_product')->where('id', $id)->update(['status' => 1]);
|
$message = '操作成功,审核通过';
|
} else {
|
Db::name('logistics_product')->where('id', $id)->update(['status' => 2]);
|
$message = '操作成功,审核不通过';
|
}
|
// 提交事务
|
Db::commit();
|
return $this->successResponse($message);
|
} else {
|
return $this->errorResponse(lang('request_method_incorrect'));
|
}
|
} catch (Exception $exc) {
|
// 回滚事务
|
Db::rollback();
|
return $this->errorResponse($exc->getMessage());
|
}
|
}
|
|
|
/**
|
* 获取物流产品列表
|
*/
|
public function logisticsProductList() {
|
if (Request::isPost()) {
|
$kw = input('kw');
|
if (!empty($kw)) {
|
$condition[] = array('product_name_cn|product_name_en|docking_code', 'like', "%$kw%");
|
}
|
$condition[] = ['status', '=', 3];
|
$p = input('p', 1);
|
$_GET['p'] = $p;
|
$other['page_size'] = input('page_size', 20);
|
$order = 'status asc,edit_time asc';
|
$count = Db::name('logistics_product')->where($condition)->count();
|
$list = Db::name('logistics_product')->field("id,platform_logistics_product_id,logistics_type,docking_system,docking_code,product_name_cn,product_name_en,value_added_services,status,edit_time")->where($condition)
|
->withAttr('edit_time', function ($value) {
|
return date('Y-m-d H:i:s', $value);
|
})->withAttr('platform_logistics_product_name', function ($value, $data) {
|
return $data['platform_logistics_product_id'] ? Db::name('platform_logistics_product')->where('id', $data['platform_logistics_product_id'])->field('product_name_cn,product_name_en,cycle_start,cycle_end')->find() : '';
|
})
|
->order($order)->page($p, $other['page_size'])->select()->toArray();
|
$other['count'] = $count;
|
|
$result['other'] = $other;
|
if (!$list) {
|
$list = [];
|
$result['code'] = 400;
|
return $result;
|
} else {
|
foreach ($list as &$item) {
|
if ($item['value_added_services']) {
|
$item['value_added_services'] = json_decode($item['value_added_services'], TRUE);
|
} else {
|
$item['value_added_services'] = [];
|
}
|
}
|
$result['code'] = 200;
|
$result['list'] = $list;
|
return $result;
|
}
|
return $result;
|
}
|
}
|
|
/**
|
* 获取增值服务列表
|
*/
|
public function logisticsVasList() {
|
if (Request::isPost()) {
|
$order = 'order_id asc,id asc';
|
$list = Db::name('logistics_vas')->field("id,vas_name,vas_code")->order($order)->cacheAlways(TRUE, 0, 'logistics_vas')->select()->toArray();
|
if (!$list) {
|
$list = [];
|
}
|
$d['code'] = 200;
|
$d['list'] = $list;
|
return $d;
|
}
|
}
|
|
}
|