You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
9.7 KiB
267 lines
9.7 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use app\common\exception\UploadException;
|
|
use app\common\library\Upload;
|
|
use app\common\model\Area;
|
|
use app\common\model\ProjectCategoryFlow;
|
|
use app\common\model\ProjectOrderFlow;
|
|
use app\common\model\ProjectWorkerOrder;
|
|
use app\common\model\ShopArea;
|
|
use app\common\model\Version;
|
|
use fast\Random;
|
|
use think\Config;
|
|
use think\Hook;
|
|
|
|
/**
|
|
* 公共接口
|
|
*/
|
|
class Common extends Api
|
|
{
|
|
|
|
protected $noNeedLogin = ['init','getAreaId','getCityList', 'signNotifyUrl','tempNotifyUrl','tempRedirectH5','tempEmptyNotifyUrl'];
|
|
protected $noNeedRight = '*';
|
|
|
|
/**
|
|
* 加载初始化
|
|
*
|
|
* @param string $version 版本号
|
|
* @param string $lng 经度
|
|
* @param string $lat 纬度
|
|
*/
|
|
public function init()
|
|
{
|
|
if ($version = $this->request->request('version')) {
|
|
$lng = $this->request->request('lng');
|
|
$lat = $this->request->request('lat');
|
|
|
|
//配置信息
|
|
$upload = Config::get('upload');
|
|
//如果非服务端中转模式需要修改为中转
|
|
if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
|
|
//临时修改上传模式为服务端中转
|
|
set_addon_config($upload['storage'], ["uploadmode" => "server"], false);
|
|
|
|
$upload = \app\common\model\Config::upload();
|
|
// 上传信息配置后
|
|
Hook::listen("upload_config_init", $upload);
|
|
|
|
$upload = Config::set('upload', array_merge(Config::get('upload'), $upload));
|
|
}
|
|
|
|
$upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true);
|
|
$upload['uploadurl'] = preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $upload['uploadurl']) ? $upload['uploadurl'] : url($upload['storage'] == 'local' ? '/api/common/upload' : $upload['uploadurl'], '', false, true);
|
|
|
|
$content = [
|
|
'citydata' => Area::getCityFromLngLat($lng, $lat),
|
|
'versiondata' => Version::check($version),
|
|
'uploaddata' => $upload,
|
|
'coverdata' => Config::get("cover"),
|
|
];
|
|
$this->success('', $content);
|
|
} else {
|
|
$this->error(__('Invalid parameters'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 上传文件
|
|
* @ApiMethod (POST)
|
|
* @param File $file 文件流
|
|
*/
|
|
public function upload()
|
|
{
|
|
Config::set('default_return_type', 'json');
|
|
//必须设定cdnurl为空,否则cdnurl函数计算错误
|
|
Config::set('upload.cdnurl', '');
|
|
$chunkid = $this->request->post("chunkid");
|
|
if ($chunkid) {
|
|
if (!Config::get('upload.chunking')) {
|
|
$this->error(__('Chunk file disabled'));
|
|
}
|
|
$action = $this->request->post("action");
|
|
$chunkindex = $this->request->post("chunkindex/d");
|
|
$chunkcount = $this->request->post("chunkcount/d");
|
|
$filename = $this->request->post("filename");
|
|
$method = $this->request->method(true);
|
|
if ($action == 'merge') {
|
|
$attachment = null;
|
|
//合并分片文件
|
|
try {
|
|
$upload = new Upload();
|
|
$attachment = $upload->merge($chunkid, $chunkcount, $filename);
|
|
} catch (UploadException $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
|
} elseif ($method == 'clean') {
|
|
//删除冗余的分片文件
|
|
try {
|
|
$upload = new Upload();
|
|
$upload->clean($chunkid);
|
|
} catch (UploadException $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
$this->success();
|
|
} else {
|
|
//上传分片文件
|
|
//默认普通上传文件
|
|
$file = $this->request->file('file');
|
|
try {
|
|
$upload = new Upload($file);
|
|
$upload->chunk($chunkid, $chunkindex, $chunkcount);
|
|
} catch (UploadException $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
$this->success();
|
|
}
|
|
} else {
|
|
$attachment = null;
|
|
//默认普通上传文件
|
|
$file = $this->request->file('file');
|
|
try {
|
|
$upload = new Upload($file);
|
|
$attachment = $upload->upload();
|
|
} catch (UploadException $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
|
|
$this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
|
}
|
|
|
|
}
|
|
|
|
//根据名称获取城市列表
|
|
public function getCityList()
|
|
{
|
|
$search = $this->request->request('search');
|
|
$page = $this->request->request('page/d', 1);
|
|
$limit= $this->request->request('limit/d', 10);
|
|
$query = ShopArea::where('level', 2)->where('disp', 1);
|
|
if ($search) {
|
|
$query->where('name', 'like', "%$search%");
|
|
}
|
|
|
|
$list = $query->field('id, name, pid')->page($page, $limit)->select();
|
|
foreach ($list as &$row) {
|
|
if ($row['name'] == '北京市' || $row['name'] == '天津市' || $row['name'] == '上海市' || $row['name'] == '重庆市') {
|
|
$row['id'] = $row['pid'];
|
|
}
|
|
$row['name'] = str_replace('市', '',$row['name']);
|
|
}
|
|
$this->success('', $list);
|
|
}
|
|
|
|
|
|
public function getAreaId(){
|
|
$params = $this->request->post();
|
|
$adcode = $params['regeocode']['addressComponent']['adcode'] ?? "";
|
|
|
|
$info = ShopArea::where('id', $adcode)->find();
|
|
if (!$info) {
|
|
$this->success('', ['area_id' => 320100]);
|
|
}
|
|
$area_id = $info['id'];
|
|
if ($info['level'] == 3) {
|
|
$info = ShopArea::where('id', $info['pid'])->find();
|
|
$area_id = $info['id'];
|
|
}
|
|
$this->success('', ['area_id' => $area_id]);
|
|
}
|
|
|
|
//签署回调 更新流程状态
|
|
public function signNotifyUrl() {
|
|
$flow_id = $this->request->get('flowId');
|
|
$order_id = $this->request->get('order_id');
|
|
$notify_data = $this->request->post();
|
|
$res = ProjectOrderFlow::where('flow_id', $flow_id)->where('order_id', $order_id)->find();
|
|
//根据业务事件处理业务状态
|
|
|
|
if (!empty($notify_data['action']) && ($notify_data['action'] == 'SIGN_FLOW_COMPLETE')) {//流程完成
|
|
if (!empty($res) && empty($res['status'])) {//接口幂等性操作 防止重复更新
|
|
$res->status = 1;
|
|
$res->update_time = time();
|
|
$res->save();
|
|
|
|
//流程所有步骤完成更新工程状态为售后 并且工单状态为已完成
|
|
$order = ProjectWorkerOrder::get($order_id);
|
|
if ($order) {
|
|
//获取完成的流程
|
|
$wc_flow = ProjectOrderFlow::where('order_id', $order_id)->where('status', 1)->count();
|
|
//待完成的流程
|
|
$dwc_flow = ProjectCategoryFlow::where('category_id', $order['category_id'])->count();
|
|
//子流程全部完成后更新工单状态
|
|
if ($dwc_flow == $wc_flow) {
|
|
$order->status = 1;
|
|
$order->build_status = '售后';
|
|
$order->save();
|
|
}
|
|
}
|
|
$this->success('success','', 200);
|
|
}
|
|
}
|
|
|
|
file_put_contents ( ROOT_PATH .'/log/' .date("Y-m-d").".log", date ( "Y-m-d H:i:s" ) . " 回调参数:" . json_encode($notify_data) . "\r\n", FILE_APPEND );
|
|
$this->success('success','', 1);
|
|
}
|
|
|
|
//模板回调
|
|
public function tempNotifyUrl() {
|
|
$flow_id = $this->request->get('flowId');
|
|
$order_id = $this->request->get('order_id');
|
|
$notify_data = $this->request->post();
|
|
$res = ProjectOrderFlow::where('flow_id', $flow_id)->where('order_id', $order_id)->find();
|
|
//更新模版填写状态
|
|
if (!empty($res)) {
|
|
$res->template_status = 1;
|
|
$res->update_time = time();
|
|
$res->save();
|
|
}
|
|
|
|
//更新文件ID
|
|
$flow = ProjectCategoryFlow::get($flow_id);
|
|
$flow->sign_fileId = $notify_data['fileId'];
|
|
$flow->save();
|
|
file_put_contents ( ROOT_PATH .'/log/' .date("Y-m-d").".log", date ( "Y-m-d H:i:s" ) . " 回调参数:" . json_encode($notify_data) . "\r\n", FILE_APPEND );
|
|
$this->success('success','', 200);
|
|
}
|
|
|
|
public function tempEmptyNotifyUrl() {
|
|
$flow_id = $this->request->get('flowId');
|
|
$order_id = $this->request->get('order_id');
|
|
$notify_data = $this->request->post();
|
|
$res = ProjectOrderFlow::where('flow_id', $flow_id)->where('order_id', $order_id)->find();
|
|
//更新模版填写状态
|
|
if (!empty($res)) {
|
|
$res->template_status = 1;
|
|
$res->update_time = time();
|
|
$res->save();
|
|
}
|
|
|
|
//更新文件ID
|
|
$flow = ProjectCategoryFlow::get($flow_id);
|
|
if (!empty($notify_data['fileId'])) {
|
|
$flow->sign_fileId = $notify_data['fileId'];
|
|
$flow->save();
|
|
file_put_contents ( ROOT_PATH .'/log/' .date("Y-m-d").".log", date ( "Y-m-d H:i:s" ) . " 回调参数:" . json_encode($notify_data) . "\r\n", FILE_APPEND );
|
|
$this->success('success','', 200);
|
|
}
|
|
|
|
$this->success('success','');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|