|
|
<?php
|
|
|
|
|
|
namespace app\admin\controller\agent;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
use app\admin\library\Auth;
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Csv;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
use think\exception\PDOException;
|
|
|
use think\exception\ValidateException;
|
|
|
use app\common\helper\HttpHelper;
|
|
|
use app\api\controller\v4\notary\Index;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*
|
|
|
* @icon fa fa-circle-o
|
|
|
*/
|
|
|
class Order extends Backend
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* Order模型对象
|
|
|
* @var \app\admin\model\agent\Order
|
|
|
*/
|
|
|
protected $model = null;
|
|
|
protected $dataLimit = 'auth';
|
|
|
protected $dataLimitField = 'admin_id';
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\admin\model\agent\Order;
|
|
|
$this->view->assign("statusList", $this->model->getStatusList());
|
|
|
$this->view->assign("userNeedTypeList", $this->model->getUserNeedTypeList());
|
|
|
$this->view->assign("recoveryStateList", $this->model->getRecoveryStateList());
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查看
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
//设置过滤方法
|
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
|
if ($this->request->isAjax()) {
|
|
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
|
|
$list = $this->model
|
|
|
->with(['type'])
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->paginate($limit);
|
|
|
|
|
|
$rows = $list->items();
|
|
|
foreach ($rows as $kk => $vv) {
|
|
|
//关联经纪人
|
|
|
if ($vv['agent_users_id'] > 0) {
|
|
|
$agent = Db::name('agent_users')
|
|
|
->where(['id' => $vv['agent_users_id']])
|
|
|
->field('id,jjr_name,jjr_mobile')
|
|
|
->find();
|
|
|
$rows[$kk]['jjr_name'] = $agent['jjr_name'] . '[' . $agent['jjr_mobile'] . ']';
|
|
|
} else {
|
|
|
$rows[$kk]['jjr_name'] = '-';
|
|
|
}
|
|
|
if ($vv['ia_pay'] == '1') {
|
|
|
$rows[$kk]['pay_times'] = setdateTimes($vv['pay_time']);
|
|
|
} else {
|
|
|
$rows[$kk]['pay_times'] = '-';
|
|
|
}
|
|
|
//关联贷款分类
|
|
|
if ($vv['loan_cat_id'] > 0) {
|
|
|
$loncat = Db::name('loan_cat')
|
|
|
->where(['id' => $vv['loan_cat_id']])
|
|
|
->find();
|
|
|
$rows[$kk]['loan_cat'] = $loncat['catname'];
|
|
|
} else {
|
|
|
$rows[$kk]['loan_cat'] = '-';
|
|
|
}
|
|
|
//关联住房性质
|
|
|
if ($vv['house_cat_id'] > 0) {
|
|
|
$housecat = Db::name('house_cat')
|
|
|
->where(['id' => $vv['house_cat_id']])
|
|
|
->find();
|
|
|
$rows[$kk]['house_cat'] = $housecat['catname'];
|
|
|
} else {
|
|
|
$rows[$kk]['house_cat'] = '-';
|
|
|
}
|
|
|
//关联当前推送到公证处状态
|
|
|
$step = Db::name('agent_order_send_logs')
|
|
|
->where(['agent_order_id' => $vv['id']])
|
|
|
->order('id', 'desc')
|
|
|
->find();
|
|
|
if (empty($step)) {
|
|
|
$sendname = '-';
|
|
|
} else {
|
|
|
if ($step['step'] == 1 && $step['send_stu'] == '0') {
|
|
|
$sendname = '用户需求推送失败';
|
|
|
}
|
|
|
if ($step['step'] == 1 && $step['send_stu'] == '1') {
|
|
|
$sendname = '用户需求推送成功';
|
|
|
}
|
|
|
if ($step['step'] == 2 && $step['send_stu'] == '0') {
|
|
|
$sendname = '不动产信息推送失败';
|
|
|
}
|
|
|
if ($step['step'] == 2 && $step['send_stu'] == '1') {
|
|
|
$sendname = '不动产信息推送成功';
|
|
|
}
|
|
|
if ($step['step'] == 3 && $step['send_stu'] == '0') {
|
|
|
$sendname = '查档报告推送失败';
|
|
|
}
|
|
|
if ($step['step'] == 3 && $step['send_stu'] == '1') {
|
|
|
$sendname = '查档报告推送成功';
|
|
|
}
|
|
|
if ($step['step'] == 4 && $step['send_stu'] == '0') {
|
|
|
$sendname = '完税报告推送失败';
|
|
|
}
|
|
|
if ($step['step'] == 4 && $step['send_stu'] == '1') {
|
|
|
$sendname = '完税报告推送成功';
|
|
|
}
|
|
|
if ($step['step'] == 5 && $step['send_stu'] == '0') {
|
|
|
$sendname = '复盘报告推送失败';
|
|
|
}
|
|
|
if ($step['step'] == 5 && $step['send_stu'] == '1') {
|
|
|
$sendname = '复盘报告推送成功';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$rows[$kk]['sendname'] = $sendname;
|
|
|
$rows[$kk]['types'] = $vv['types'] > '0' ? $vv['types'] : '-';
|
|
|
$rows[$kk]['agent_user'] = $vv['agent_user'] > '0' ? $vv['agent_user'] : '-';
|
|
|
$rows[$kk]['mobile'] = $vv['mobile'] > '0' ? $vv['mobile'] : '-';
|
|
|
$rows[$kk]['content'] = $vv['content'] > '0' ? $vv['content'] : '';
|
|
|
$rows[$kk]['remark'] = $vv['remark'] > '0' ? $vv['remark'] : '';
|
|
|
}
|
|
|
|
|
|
$result = array("total" => $list->total(), "rows" => $rows);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
public function add()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
$params = $this->preExcludeFields($params);
|
|
|
$params['order_nunber'] = getOrderSn();
|
|
|
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
$params[$this->dataLimitField] = $this->auth->id;
|
|
|
}
|
|
|
//判断是否选择了经纪人,选择了经纪人,添加工单所属企业
|
|
|
if ($params['agent_users_id'] > 0) {
|
|
|
$params['admin_id'] = agent_users_admin_id($params['agent_users_id']);
|
|
|
}
|
|
|
//获得企业名称
|
|
|
if ($params['agent_order_type_id'] == '1' && $params['agent_name'] > 0) {
|
|
|
$agent = Db::name('agent_list')
|
|
|
->where(['id' => $params['agent_name']])
|
|
|
->field('id,agent_name')
|
|
|
->find();
|
|
|
$params['agent_name'] = $agent['agent_name'];
|
|
|
}
|
|
|
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
//是否采用模型验证
|
|
|
if ($this->modelValidate) {
|
|
|
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
$this->model->validateFailException(true)->validate($validate);
|
|
|
}
|
|
|
$result = $this->model->allowField(true)->save($params);
|
|
|
Db::commit();
|
|
|
} catch (ValidateException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (PDOException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
if ($result !== false) {
|
|
|
//审核通过并指定了经纪人
|
|
|
if (($params['status'] == '1' || $params['status'] == '3') && $params['agent_users_id'] > 0) {
|
|
|
//获得工单分类名称
|
|
|
$ordertype = Db::name('agent_order_type')
|
|
|
->where(['id' => $params['agent_order_type_id']])
|
|
|
->find();
|
|
|
$jjr_name = Db::name('agent_users')
|
|
|
->where(['id' => $params['agent_users_id']])
|
|
|
->value('jjr_name');
|
|
|
$titdesc = '系统指派工单[' . $ordertype['title'] . ']';
|
|
|
$sendInfo = array(
|
|
|
'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"),
|
|
|
'keyword1' => array('value' => urlencode($params['order_nunber']), 'color' => '#173177'),
|
|
|
'keyword2' => array('value' => urlencode('已指派,待处理'), 'color' => '#173177'),
|
|
|
'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'),
|
|
|
'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'),
|
|
|
);
|
|
|
$wxopenid = getAgetWxOpenid($params['agent_users_id']);
|
|
|
if ($wxopenid) {
|
|
|
$config = get_addon_config('wechat');
|
|
|
$tourl = 'https://fdc.xp.yn.cn/h5/';
|
|
|
$ywt_appid = 'wxe1355bcf5af1bea3';
|
|
|
$pagepath = 'pages/home/wait/kind?id=' . $this->model->id . '&type=' . $params['agent_order_type_id'] . '&index=1';
|
|
|
$res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath);
|
|
|
file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-1-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
}
|
|
|
}
|
|
|
$this->success();
|
|
|
} else {
|
|
|
$this->error(__('No rows were inserted'));
|
|
|
}
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/***
|
|
|
* 编辑(old)
|
|
|
*
|
|
|
*/
|
|
|
// public function edit($ids = null)
|
|
|
// {
|
|
|
// $row = $this->model->get($ids);
|
|
|
// $row['types'] = $row['types'] > '0' ? $row['types'] : '';
|
|
|
// $row['agent_user'] = $row['agent_user'] > '0' ? $row['agent_user'] : '';
|
|
|
// $row['mobile'] = $row['mobile'] > '0' ? $row['mobile'] : '';
|
|
|
// $row['content'] = $row['content'] > '0' ? $row['content'] : '';
|
|
|
// $row['remark'] = $row['remark'] > '0' ? $row['remark'] : '';
|
|
|
// if (!$row) {
|
|
|
// $this->error(__('No Results were found'));
|
|
|
// }
|
|
|
// $adminIds = $this->getDataLimitAdminIds();
|
|
|
// if (is_array($adminIds)) {
|
|
|
// if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
// $this->error(__('You have no permission'));
|
|
|
// }
|
|
|
// }
|
|
|
// if ($this->request->isPost()) {
|
|
|
// $params = $this->request->post("row/a");
|
|
|
// if ($params) {
|
|
|
// $params = $this->preExcludeFields($params);
|
|
|
// //判断是否选择了经纪人,选择了经纪人,添加工单所属企业
|
|
|
// if ($params['agent_users_id'] > 0) {
|
|
|
// $params['admin_id'] = agent_users_admin_id($params['agent_users_id']);
|
|
|
// }
|
|
|
// $result = false;
|
|
|
// Db::startTrans();
|
|
|
// try {
|
|
|
// //是否采用模型验证
|
|
|
// if ($this->modelValidate) {
|
|
|
// $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
// $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
// $row->validateFailException(true)->validate($validate);
|
|
|
// }
|
|
|
// if ($params['status'] == 1 && $params['agent_users_id'] > 0) {
|
|
|
// $params['status'] = 3;
|
|
|
// }
|
|
|
//
|
|
|
// $result = $row->save($params);
|
|
|
// if ($params['status'] == 1) {
|
|
|
// $str = '工单通过审核';
|
|
|
// }
|
|
|
// if ($params['status'] == 2) {
|
|
|
// $str = '工单未通过审核';
|
|
|
// }
|
|
|
// if ($params['status'] == 3) {
|
|
|
// $str = '工单已指派';
|
|
|
// }
|
|
|
// if ($params['status'] == 8) {
|
|
|
// $str = '工单不通过,退款金额原路返回';
|
|
|
// }
|
|
|
//
|
|
|
// Db::name('agent_order_log')->insert([
|
|
|
// 'agent_order_id' => $ids,
|
|
|
// 'admin_id' => $this->auth->id,
|
|
|
// 'content' => $str,
|
|
|
// 'createtime' => time(),
|
|
|
// 'step' => 2,
|
|
|
// 'agent_user_id' => $params['agent_users_id'] ? $params['agent_users_id'] : 0,
|
|
|
// ]);
|
|
|
//
|
|
|
// //判断是否已支付,已支付则退款
|
|
|
// if ($params['status'] == 8 && $row['ia_pay'] == '1') {
|
|
|
// //支付金额
|
|
|
// $paylog = Db::name('workorder_userpay')
|
|
|
// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']])
|
|
|
// ->find();
|
|
|
// if (!empty($paylog)) {
|
|
|
// //退款处理
|
|
|
// $pay_fee = $paylog['price'];
|
|
|
// $refund_fee = $pay_fee;
|
|
|
// $order_sn = $paylog['ordersn'];
|
|
|
// $pay_type = 'wechat';
|
|
|
// $reason = '工单审核不通过,退回保证金';
|
|
|
// $notifyurl = 'https://fdc.xp.yn.cn/api/index/refundNotifyx';//退款回调地址
|
|
|
// //直接调用退款方法传参即可
|
|
|
// $response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($paylog['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp');
|
|
|
// $response = json_encode($response);
|
|
|
// $response = json_decode($response, true);
|
|
|
// file_put_contents("pcl_repay_fdc_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
// if (!empty($response['return_code'] == 'SUCCESS')) {
|
|
|
// //退款成功,更新退款记录
|
|
|
// $addtime = time();
|
|
|
// $relogs['uptime'] = $addtime;
|
|
|
// $relogs['is_refund'] = 1;
|
|
|
// $relogs['out_refund_no'] = $response['out_refund_no'];
|
|
|
// $relogs['refund_id'] = $response['refund_id'];
|
|
|
// $relogs['refund_fee'] = $response['refund_fee'];
|
|
|
// $relogs['refund_time'] = $addtime;
|
|
|
// $relogs['admin'] = $this->auth->id;
|
|
|
// Db::name('workorder_userpay')
|
|
|
// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']])
|
|
|
// ->update($relogs);
|
|
|
// //更新工单表
|
|
|
// $order['is_refund'] = 1;
|
|
|
// $order['refund_time'] = $addtime;
|
|
|
// Db::name('agent_order')
|
|
|
// ->where(['id' => $row['id']])
|
|
|
// ->update($order);
|
|
|
// } else {
|
|
|
// $this->error('退款失败');
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// Db::commit();
|
|
|
// } catch (ValidateException $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// } catch (PDOException $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// } catch (Exception $e) {
|
|
|
// Db::rollback();
|
|
|
// $this->error($e->getMessage());
|
|
|
// }
|
|
|
// if ($result !== false) {
|
|
|
// //审核通过并指定了经纪人
|
|
|
// if (($params['status'] == '1' || $params['status'] == '3') && $params['agent_users_id'] > 0) {
|
|
|
// //获得工单分类名称
|
|
|
// $ordertype = Db::name('agent_order_type')
|
|
|
// ->where(['id' => $params['agent_order_type_id']])
|
|
|
// ->find();
|
|
|
// $jjr_name = Db::name('agent_users')
|
|
|
// ->where(['id' => $params['agent_users_id']])
|
|
|
// ->value('jjr_name');
|
|
|
// $titdesc = '系统指派工单[' . $ordertype['title'] . ']';
|
|
|
// $sendInfo = array(
|
|
|
// 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"),
|
|
|
// 'keyword1' => array('value' => urlencode($row['order_nunber']), 'color' => '#173177'),
|
|
|
// 'keyword2' => array('value' => urlencode('已指派,待处理'), 'color' => '#173177'),
|
|
|
// 'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'),
|
|
|
// 'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'),
|
|
|
// );
|
|
|
// $wxopenid = getAgetWxOpenid($params['agent_users_id']);
|
|
|
// if ($wxopenid) {
|
|
|
// $config = get_addon_config('wechat');
|
|
|
// $tourl = 'https://fdc.xp.yn.cn/h5/';
|
|
|
// $ywt_appid = 'wxe1355bcf5af1bea3';
|
|
|
// $pagepath = 'pages/home/wait/kind?id=' . $row['id'] . '&type=' . $params['agent_order_type_id'] . '&index=1';
|
|
|
// $res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath);
|
|
|
// file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
// }
|
|
|
// }
|
|
|
// $this->success();
|
|
|
// } else {
|
|
|
// $this->error(__('No rows were updated'));
|
|
|
// }
|
|
|
// }
|
|
|
// $this->error(__('Parameter %s can not be empty', ''));
|
|
|
// }
|
|
|
// $this->view->assign("row", $row);
|
|
|
// return $this->view->fetch();
|
|
|
// }
|
|
|
|
|
|
/***
|
|
|
* 编辑
|
|
|
*
|
|
|
*/
|
|
|
public function edit($ids = null)
|
|
|
{
|
|
|
$row = $this->model->get($ids);
|
|
|
$row['types'] = $row['types'] > '0' ? $row['types'] : '';
|
|
|
$row['agent_user'] = $row['agent_user'] > '0' ? $row['agent_user'] : '';
|
|
|
$row['mobile'] = $row['mobile'] > '0' ? $row['mobile'] : '';
|
|
|
$row['content'] = $row['content'] > '0' ? $row['content'] : '';
|
|
|
$row['remark'] = $row['remark'] > '0' ? $row['remark'] : '';
|
|
|
//获得推送公证处状态
|
|
|
$step = Db::name('agent_order_send_logs')
|
|
|
->where(['agent_order_id' => $row['id']])
|
|
|
->order('id', 'desc')
|
|
|
->find();
|
|
|
|
|
|
if (!$row) {
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
$adminIds = $this->getDataLimitAdminIds();
|
|
|
if (is_array($adminIds)) {
|
|
|
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
$this->error(__('You have no permission'));
|
|
|
}
|
|
|
}
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
$params = $this->preExcludeFields($params);
|
|
|
//判断是否选择了经纪人,选择了经纪人,添加工单所属企业
|
|
|
if ($params['agent_users_id'] > 0) {
|
|
|
$params['admin_id'] = agent_users_admin_id($params['agent_users_id']);
|
|
|
}
|
|
|
if (isset($params['pclOfficeSendv2'])) {
|
|
|
$pclOfficeSendv2 = $params['pclOfficeSendv2'];
|
|
|
unset($params['pclOfficeSendv2']);
|
|
|
}
|
|
|
if (isset($params['pclOfficeSendv3'])) {
|
|
|
$pclOfficeSendv3 = $params['pclOfficeSendv3'];
|
|
|
unset($params['pclOfficeSendv3']);
|
|
|
}
|
|
|
if (isset($params['pclOfficeSendv4'])) {
|
|
|
$pclOfficeSendv4 = $params['pclOfficeSendv4'];
|
|
|
unset($params['pclOfficeSendv4']);
|
|
|
}
|
|
|
if (isset($params['pclOfficeSendv5'])) {
|
|
|
$pclOfficeSendv5 = $params['pclOfficeSendv5'];
|
|
|
unset($params['pclOfficeSendv5']);
|
|
|
}
|
|
|
$result = false;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
//是否采用模型验证
|
|
|
if ($this->modelValidate) {
|
|
|
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
$row->validateFailException(true)->validate($validate);
|
|
|
}
|
|
|
|
|
|
$result = $row->save($params);
|
|
|
$statusList = $this->model->getStatusList();
|
|
|
$str = $statusList[$params['status']];
|
|
|
|
|
|
$step_id = 0;
|
|
|
$step = Db::name("agent_order_log")->where("agent_order_id", $ids)->order("step desc,id desc")->value("step");
|
|
|
if ($step) {
|
|
|
$step_id = $step + 1;
|
|
|
}
|
|
|
|
|
|
Db::name('agent_order_log')->insert([
|
|
|
'agent_order_id' => $ids,
|
|
|
'content' => $str,
|
|
|
'user_id' => $row['user_id'],
|
|
|
'createtime' => time(),
|
|
|
'admin_id' => agent_users_admin_id($params['agent_users_id']),
|
|
|
'step' => $step_id,
|
|
|
'write_status' => $params['status'],
|
|
|
'agent_user_id' => $params['agent_users_id'] ? $params['agent_users_id'] : 0,
|
|
|
]);
|
|
|
|
|
|
//判断是否已支付,已支付则退款
|
|
|
// if ($params['status'] == 8 && $row['ia_pay'] == '1') {
|
|
|
// //支付金额
|
|
|
// $paylog = Db::name('workorder_userpay')
|
|
|
// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']])
|
|
|
// ->find();
|
|
|
// if (!empty($paylog)) {
|
|
|
// //退款处理
|
|
|
// $pay_fee = $paylog['price'];
|
|
|
// $refund_fee = $pay_fee;
|
|
|
// $order_sn = $paylog['ordersn'];
|
|
|
// $pay_type = 'wechat';
|
|
|
// $reason = '工单审核不通过,退回保证金';
|
|
|
// $notifyurl = 'https://fdc.xp.yn.cn/api/index/refundNotifyx';//退款回调地址
|
|
|
// //直接调用退款方法传参即可
|
|
|
// $response = \addons\epay\library\Service::submitRefund($pay_fee, $refund_fee, $order_sn, getRefundSn($paylog['user_id']), $pay_type, $reason, $notifyurl, '', 'miniapp');
|
|
|
// $response = json_encode($response);
|
|
|
// $response = json_decode($response, true);
|
|
|
// file_put_contents("pcl_repay_fdc_v2.log", date("Y-m-d H:i:s") . "::" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
// if (!empty($response['return_code'] == 'SUCCESS')) {
|
|
|
// //退款成功,更新退款记录
|
|
|
// $addtime = time();
|
|
|
// $relogs['uptime'] = $addtime;
|
|
|
// $relogs['is_refund'] = 1;
|
|
|
// $relogs['out_refund_no'] = $response['out_refund_no'];
|
|
|
// $relogs['refund_id'] = $response['refund_id'];
|
|
|
// $relogs['refund_fee'] = $response['refund_fee'];
|
|
|
// $relogs['refund_time'] = $addtime;
|
|
|
// $relogs['admin'] = $this->auth->id;
|
|
|
// Db::name('workorder_userpay')
|
|
|
// ->where(['work_id' => $row['id'], 'ordersn' => $row['order_nunber']])
|
|
|
// ->update($relogs);
|
|
|
// //更新工单表
|
|
|
// $order['is_refund'] = 1;
|
|
|
// $order['refund_time'] = $addtime;
|
|
|
// Db::name('agent_order')
|
|
|
// ->where(['id' => $row['id']])
|
|
|
// ->update($order);
|
|
|
// } else {
|
|
|
// $this->error('退款失败');
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
Db::commit();
|
|
|
} catch (ValidateException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (PDOException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
if ($result !== false) {
|
|
|
//获得工单信息
|
|
|
$orders = Db::name('agent_order')->where(['id' => $row['id']])->find();
|
|
|
$titdesc = $orders['order_nunber'];
|
|
|
if ($params['status'] == '1') {
|
|
|
$titdesc = '工单审核通过';
|
|
|
}
|
|
|
if ($params['status'] == '2') {
|
|
|
$titdesc = '工单审核被拒绝';
|
|
|
}
|
|
|
|
|
|
|
|
|
//第1步 用户需求信息审核成功,调用接口推给公证处
|
|
|
$Office = new Index();
|
|
|
if ($params['status'] == '1') {
|
|
|
$titdesc = '工单审核通过,公证处办理中';
|
|
|
//判断是否推送过了,推送日志表agent_order_send_logs
|
|
|
$cks_send = Db::name('agent_order_send_logs')
|
|
|
->where(['agent_order_id' => $row['id'], 'send_stu' => 1, 'step' => 1])
|
|
|
->find();
|
|
|
if (empty($cks_send)) {
|
|
|
//1获得token
|
|
|
$token = $Office->getOfficeToken();
|
|
|
while (empty($token)) {
|
|
|
$token = $Office->getOfficeToken();
|
|
|
}
|
|
|
//获得推送数据
|
|
|
$sendData = $Office->notifyNewOrder($row['id']);
|
|
|
|
|
|
$url = "https://gz.hxgzc.cn:34443/capitalManage/services/createOrder";
|
|
|
if (!empty($token) && !empty($sendData)) {
|
|
|
$res = HttpHelper::curl($url, 'POST', $sendData, [], $token);
|
|
|
$resArr = json_decode(stripslashes($res), true);
|
|
|
|
|
|
if ($resArr['succeed'] == true) {
|
|
|
$slogs['send_stu'] = 1;
|
|
|
} else {
|
|
|
$slogs['send_stu'] = 0;
|
|
|
}
|
|
|
$slogs['agent_order_id'] = $row['id'];
|
|
|
$slogs['createtime'] = time();
|
|
|
$slogs['step'] = 1;
|
|
|
$slogs['reback_msg'] = $res;
|
|
|
|
|
|
$logs = Db::name('agent_order_send_logs')->insertGetId($slogs);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//2、不动产信息审核通过,推送公证处
|
|
|
if ($pclOfficeSendv2 == 1) {
|
|
|
$titdesc = '不动产信息审核通过,公证处办理中';
|
|
|
//1获得token
|
|
|
$token = $Office->getOfficeToken();
|
|
|
while (empty($token)) {
|
|
|
$token = $Office->getOfficeToken();
|
|
|
}
|
|
|
//获得推送数据
|
|
|
$sendData = $Office->realEstateUpdate($row['id']);
|
|
|
|
|
|
$url = "https://gz.hxgzc.cn:34443/capitalManage/services/realEstateUpdate";
|
|
|
if (!empty($token) && !empty($sendData)) {
|
|
|
$res = HttpHelper::curl($url, 'POST', $sendData, [], $token);
|
|
|
$resArr = json_decode(stripslashes($res), true);
|
|
|
|
|
|
if ($resArr['succeed'] == true) {
|
|
|
$slogs['send_stu'] = 1;
|
|
|
} else {
|
|
|
$slogs['send_stu'] = 0;
|
|
|
}
|
|
|
$slogs['agent_order_id'] = $row['id'];
|
|
|
$slogs['createtime'] = time();
|
|
|
$slogs['step'] = 2;
|
|
|
$slogs['reback_msg'] = $res;
|
|
|
|
|
|
$logs = Db::name('agent_order_send_logs')->insertGetId($slogs);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//3、推送查档报告
|
|
|
if ($pclOfficeSendv3 == 1) {
|
|
|
$titdesc = '查档报告审核通过,公证处办理中';
|
|
|
//1获得token
|
|
|
$token = $Office->getOfficeToken();
|
|
|
while (empty($token)) {
|
|
|
$token = $Office->getOfficeToken();
|
|
|
}
|
|
|
//获得推送数据
|
|
|
$sendData = $Office->checkReportUpdate($row['id']);
|
|
|
|
|
|
$url = "https://gz.hxgzc.cn:34443/capitalManage/services/checkReportUpdate";
|
|
|
if (!empty($token) && !empty($sendData)) {
|
|
|
$res = HttpHelper::curl($url, 'POST', $sendData, [], $token);
|
|
|
$resArr = json_decode(stripslashes($res), true);
|
|
|
|
|
|
if ($resArr['succeed'] == true) {
|
|
|
$slogs['send_stu'] = 1;
|
|
|
} else {
|
|
|
$slogs['send_stu'] = 0;
|
|
|
}
|
|
|
$slogs['agent_order_id'] = $row['id'];
|
|
|
$slogs['createtime'] = time();
|
|
|
$slogs['step'] = 3;
|
|
|
$slogs['reback_msg'] = $res;
|
|
|
|
|
|
$logs = Db::name('agent_order_send_logs')->insertGetId($slogs);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//4、推送完税报告
|
|
|
if ($pclOfficeSendv4 == 1) {
|
|
|
$titdesc = '完税报告审核通过,公证处办理中';
|
|
|
//1获得token
|
|
|
$token = $Office->getOfficeToken();
|
|
|
while (empty($token)) {
|
|
|
$token = $Office->getOfficeToken();
|
|
|
}
|
|
|
//获得推送数据
|
|
|
$sendData = $Office->taxPaidReportUpdate($row['id']);
|
|
|
|
|
|
$url = "https://gz.hxgzc.cn:34443/capitalManage/services/taxPaidReportUpdate";
|
|
|
if (!empty($token) && !empty($sendData)) {
|
|
|
$res = HttpHelper::curl($url, 'POST', $sendData, [], $token);
|
|
|
$resArr = json_decode(stripslashes($res), true);
|
|
|
|
|
|
if ($resArr['succeed'] == true) {
|
|
|
$slogs['send_stu'] = 1;
|
|
|
} else {
|
|
|
$slogs['send_stu'] = 0;
|
|
|
}
|
|
|
$slogs['agent_order_id'] = $row['id'];
|
|
|
$slogs['createtime'] = time();
|
|
|
$slogs['step'] = 4;//
|
|
|
$slogs['reback_msg'] = $res;
|
|
|
|
|
|
$logs = Db::name('agent_order_send_logs')->insertGetId($slogs);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
//5、推送复盘报告
|
|
|
if ($pclOfficeSendv5 == 1) {
|
|
|
$titdesc = '复盘信息审核通过,公证处办理中';
|
|
|
//1获得token
|
|
|
$token = $Office->getOfficeToken();
|
|
|
while (empty($token)) {
|
|
|
$token = $Office->getOfficeToken();
|
|
|
}
|
|
|
//获得推送数据
|
|
|
$sendData = $Office->orderMatchReportUpdate($row['id']);
|
|
|
|
|
|
$url = "https://gz.hxgzc.cn:34443/capitalManage/services/orderMatchReportUpdate";
|
|
|
if (!empty($token) && !empty($sendData)) {
|
|
|
$res = HttpHelper::curl($url, 'POST', $sendData, [], $token);
|
|
|
$resArr = json_decode(stripslashes($res), true);
|
|
|
|
|
|
if ($resArr['succeed'] == true) {
|
|
|
$slogs['send_stu'] = 1;
|
|
|
} else {
|
|
|
$slogs['send_stu'] = 0;
|
|
|
}
|
|
|
$slogs['agent_order_id'] = $row['id'];
|
|
|
$slogs['createtime'] = time();
|
|
|
$slogs['step'] = 5;//复盘
|
|
|
$slogs['reback_msg'] = $res;
|
|
|
|
|
|
$logs = Db::name('agent_order_send_logs')->insertGetId($slogs);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//审核通过并指定了经纪人
|
|
|
// if (($params['status'] == '1' || $params['status'] == '3') && $params['agent_users_id'] > 0) {
|
|
|
// //获得工单分类名称
|
|
|
// $ordertype = Db::name('agent_order_type')
|
|
|
// ->where(['id' => $params['agent_order_type_id']])
|
|
|
// ->find();
|
|
|
// $jjr_name = Db::name('agent_users')
|
|
|
// ->where(['id' => $params['agent_users_id']])
|
|
|
// ->value('jjr_name');
|
|
|
// $titdesc = '系统指派工单[' . $ordertype['title'] . ']';
|
|
|
// $sendInfo = array(
|
|
|
// 'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"),
|
|
|
// 'keyword1' => array('value' => urlencode($row['order_nunber']), 'color' => '#173177'),
|
|
|
// 'keyword2' => array('value' => urlencode('已指派,待处理'), 'color' => '#173177'),
|
|
|
// 'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'),
|
|
|
// 'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'),
|
|
|
// );
|
|
|
// $wxopenid = getAgetWxOpenid($params['agent_users_id']);
|
|
|
// if ($wxopenid) {
|
|
|
// $config = get_addon_config('wechat');
|
|
|
// $tourl = 'https://fdc.xp.yn.cn/h5/';
|
|
|
// $ywt_appid = 'wxe1355bcf5af1bea3';
|
|
|
// $pagepath = 'pages/home/wait/kind?id=' . $row['id'] . '&type=' . $params['agent_order_type_id'] . '&index=1';
|
|
|
// $res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath);
|
|
|
// file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
//推送公众号模板信息给工单管理经纪人
|
|
|
$this->senWxmsgToAgentUser($orders, $titdesc);
|
|
|
$this->success();
|
|
|
} else {
|
|
|
$this->error(__('No rows were updated'));
|
|
|
}
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
$this->view->assign("row", $row);
|
|
|
$this->view->assign("step", $step);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/***
|
|
|
* 公众号推送工单信息给经纪人
|
|
|
*/
|
|
|
private function senWxmsgToAgentUser($order, $titdesc)
|
|
|
{
|
|
|
//获得工单分类名称
|
|
|
$ordertype = Db::name('agent_order_type')
|
|
|
->where(['id' => $order['agent_order_type_id']])
|
|
|
->find();
|
|
|
$jjr_name = Db::name('agent_users')
|
|
|
->where(['id' => $order['agent_users_id']])
|
|
|
->value('jjr_name');
|
|
|
$sendInfo = array(
|
|
|
'first' => array('value' => urlencode($titdesc), 'color' => "#743A3A"),
|
|
|
'keyword1' => array('value' => urlencode($order['order_nunber']), 'color' => '#173177'),
|
|
|
'keyword2' => array('value' => urlencode($titdesc), 'color' => '#173177'),
|
|
|
'keyword3' => array('value' => urlencode($jjr_name), 'color' => '#173177'),
|
|
|
'remark' => array('value' => urlencode('处理时间:' . date('Y-m-d H:i:s', time())), 'color' => '#173177'),
|
|
|
);
|
|
|
$wxopenid = getAgetWxOpenid($order['agent_users_id']);
|
|
|
if ($wxopenid) {
|
|
|
$config = get_addon_config('wechat');
|
|
|
$tourl = 'https://fdc.xp.yn.cn/h5/';
|
|
|
$ywt_appid = 'wxe1355bcf5af1bea3';
|
|
|
$pagepath = 'pages/order/order_details?id=' . $order['id'];
|
|
|
$res = sendWxMsgToAgent($sendInfo, $wxopenid, $tourl, $config['app_id'], $config['secret'], $ywt_appid, $pagepath);
|
|
|
//file_put_contents("pcl_wct_send.log", date("Y-m-d H:i:s") . "1-2-" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导入excel数据
|
|
|
*/
|
|
|
public function import()
|
|
|
{
|
|
|
|
|
|
$file = $this->request->request('file');
|
|
|
if (!$file) {
|
|
|
$this->error(__('Parameter %s can not be empty', 'file'));
|
|
|
}
|
|
|
$filePath = ROOT_PATH . DS . 'public' . DS . $file;
|
|
|
if (!is_file($filePath)) {
|
|
|
$this->error(__('No results were found'));
|
|
|
}
|
|
|
|
|
|
if (!is_file($filePath)) {
|
|
|
$this->error('找不到数据文件,请重新上传');
|
|
|
}
|
|
|
|
|
|
//实例化reader
|
|
|
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
|
|
|
if (!in_array($ext, ['xls', 'xlsx'])) {
|
|
|
$this->error('不支持的数据格式');
|
|
|
}
|
|
|
if ($ext === 'xls') {
|
|
|
$reader = new Xls();
|
|
|
} else {
|
|
|
$reader = new Xlsx();
|
|
|
}
|
|
|
//读取EXCEl的内容
|
|
|
$PHPExcel = $reader->load($filePath);
|
|
|
if (!$PHPExcel) {
|
|
|
$this->error('表格内没有数据内容');
|
|
|
}
|
|
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
|
|
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
|
|
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
|
|
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
|
|
|
$fields = [];
|
|
|
//获得表第1行栏目名称
|
|
|
for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
|
|
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
|
|
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
|
|
|
$fields[] = $val;
|
|
|
}
|
|
|
}
|
|
|
//获得从第2行起内容列表数组
|
|
|
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
|
|
|
$values = [];
|
|
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
|
|
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
|
|
|
$values[] = is_null($val) ? '0' : $val;
|
|
|
}
|
|
|
|
|
|
//循环保存数据到数据库
|
|
|
$data['agent_order_type_id'] = $this->getcatIds($values[1]);
|
|
|
$data['order_nunber'] = getOrderSn();
|
|
|
|
|
|
$data['user_name'] = $values[2];
|
|
|
$data['cqr_mobile'] = $values[3];
|
|
|
$data['agent_user'] = $values[4];
|
|
|
$data['mobile'] = $values[5] > '0' ? $values[5] : '';
|
|
|
|
|
|
if ($data['agent_order_type_id'] == 5 && $values[6] > '0') {
|
|
|
$data['loan_cat_id'] = $this->getLoancatIds($values[6]);
|
|
|
} else {
|
|
|
$data['loan_cat_id'] = '';
|
|
|
}
|
|
|
if ($data['agent_order_type_id'] == 1 && $values[7] > '0') {
|
|
|
$data['house_cat_id'] = $this->getHousecatIds($values[7]);
|
|
|
} else {
|
|
|
$data['house_cat_id'] = '';
|
|
|
}
|
|
|
|
|
|
$data['agent_name'] = $values[8] > '0' ? $values[8] : '';
|
|
|
$data['agent_user_name'] = $values[9] > '0' ? $values[9] : '';
|
|
|
$data['agent_mobile'] = $values[10] > '0' ? $values[10] : '';
|
|
|
|
|
|
$data['house_area'] = $values[11] > '0' ? $values[11] : '';
|
|
|
$data['house_price'] = $values[12] > '0' ? $values[12] : '';
|
|
|
|
|
|
$data['content'] = $values[13] > '0' ? $values[13] : '';
|
|
|
$data['remark'] = $values[14] > '0' ? $values[14] : '';
|
|
|
|
|
|
$data['is_import'] = 1;
|
|
|
$data['createtime'] = time();
|
|
|
|
|
|
//判断订单号是否存在
|
|
|
$cks = Db::name('agent_order')
|
|
|
->where(['order_nunber' => $data['order_nunber']])
|
|
|
->find();
|
|
|
if (empty($cks)) {
|
|
|
$rs = Db::name('agent_order')->insertGetId($data);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
$this->success('导入成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 配置分类
|
|
|
* 工单分类
|
|
|
*/
|
|
|
protected function getcatIds($data)
|
|
|
{
|
|
|
$wh['title'] = ['=', $data];
|
|
|
$cat = Db::name('agent_order_type')
|
|
|
->where($wh)
|
|
|
->find();
|
|
|
if (empty($cat)) {
|
|
|
$wh2['title'] = ['like', '%' . $data . '%'];
|
|
|
$cat = Db::name('agent_order_type')
|
|
|
->where($wh2)
|
|
|
->find();
|
|
|
}
|
|
|
$cat_id = !empty($cat) ? $cat['id'] : 1;
|
|
|
|
|
|
return $cat_id;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 贷款分类
|
|
|
*
|
|
|
*/
|
|
|
protected function getLoancatIds($data)
|
|
|
{
|
|
|
$wh['catname'] = ['=', $data];
|
|
|
$cat = Db::name('loan_cat')
|
|
|
->where($wh)
|
|
|
->find();
|
|
|
if (empty($cat)) {
|
|
|
$wh2['catname'] = ['like', '%' . $data . '%'];
|
|
|
$cat = Db::name('loan_cat')
|
|
|
->where($wh2)
|
|
|
->find();
|
|
|
}
|
|
|
$cat_id = !empty($cat) ? $cat['id'] : 1;
|
|
|
|
|
|
return $cat_id;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 房子性质分类
|
|
|
*
|
|
|
*/
|
|
|
protected function getHousecatIds($data)
|
|
|
{
|
|
|
$wh['catname'] = ['=', $data];
|
|
|
$cat = Db::name('house_cat')
|
|
|
->where($wh)
|
|
|
->find();
|
|
|
if (empty($cat)) {
|
|
|
$wh2['catname'] = ['like', '%' . $data . '%'];
|
|
|
$cat = Db::name('house_cat')
|
|
|
->where($wh2)
|
|
|
->find();
|
|
|
}
|
|
|
$cat_id = !empty($cat) ? $cat['id'] : 1;
|
|
|
|
|
|
return $cat_id;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|