提交 50421061 authored 作者: 李大见's avatar 李大见

充值,仓库,售后,账单

上级 19544188
<?php
namespace App\Http\Controllers\Api\MobileWeb;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Validators\Api\MobileWeb\AftersaleOrderValidator;
use BlueCity\Core\Inc\ErrorInc;
use App\Services\Api\MobileWeb\AftersaleOrderService;
use App\Services\DealPicService;
// 移动端-售后单
class AftersaleOrderController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
public function __construct()
{
$this->dataValidator = new AftersaleOrderValidator();
}
/**
* 售后列表
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function index(Request $request) {
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = AftersaleOrderService::index($request->all(), $this->show_count,1);
return response()->json($return_data);
}
/**
* 售后立即处理
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function handle_ive(Request $request) {
// 验证数据
$error_message = $this->dataValidator->handle_iveValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::handle_ive($data);
return response()->json($return_data);
}
/**
* 日常反馈
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function dailyFeedback(Request $request) {
// 验证数据
$error_message = $this->dataValidator->dailyFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::dailyFeedback($data);
return response()->json($return_data);
}
/**
* 申请完成
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function quality (Request $request) {
// 验证数据
$error_message = $this->dataValidator->dailyFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::quality($data);
return response()->json($return_data);
}
/**
* 上传图片
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
*/
public function upload(Request $request)
{
$session = $request['session'];
// if (empty($request['file'])) {
// return response()->json(['ErrorCode' => 2, 'ErrorMessage' => '请上传文件', 'Data' => []]);
// }
$request['path'] = './afterSale/'.date('Ym');
$return_data = DealPicService::upload($request);
if ($return_data['code'] == 200) {
return response()->json(['ErrorCode' => 1, 'ErrorMessage' => '上传成功', 'Data' => $return_data['data']]);
} else {
return response()->json(['ErrorCode' => 2, 'ErrorMessage' => $return_data['msg'], 'Data' => '']);
}
}
/**
* 详情
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function info (Request $request) {
// 验证数据
$error_message = $this->dataValidator->infoValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::info($data);
return response()->json($return_data);
}
}
<?php
namespace App\Http\Controllers\Api\MobileWeb;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\Validators\Api\MobileWeb\StatementsListValidator;
use BlueCity\Core\Inc\ErrorInc;
use App\Services\Api\MobileWeb\StatementsListService;
use App\Services\DealPicService;
// 移动端-账单
class StatementsListController extends Controller
{
// 列表每页显示数据个数
protected $show_count = 10;
public function __construct()
{
$this->dataValidator = new StatementsListValidator();
}
/**
* 售后列表
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function index(Request $request) {
// 验证数据
$error_message = $this->dataValidator->indexValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$return_data = StatementsListService::index($request->all(), $this->show_count,1);
return response()->json($return_data);
}
/**
* 售后立即处理
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function handle_ive(Request $request) {
// 验证数据
$error_message = $this->dataValidator->handle_iveValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::handle_ive($data);
return response()->json($return_data);
}
/**
* 日常反馈
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function dailyFeedback(Request $request) {
// 验证数据
$error_message = $this->dataValidator->dailyFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::dailyFeedback($data);
return response()->json($return_data);
}
/**
* 申请完成
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function quality (Request $request) {
// 验证数据
$error_message = $this->dataValidator->dailyFeedbackValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::quality($data);
return response()->json($return_data);
}
/**
* 上传图片
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
*/
public function upload(Request $request)
{
$session = $request['session'];
// if (empty($request['file'])) {
// return response()->json(['ErrorCode' => 2, 'ErrorMessage' => '请上传文件', 'Data' => []]);
// }
$request['path'] = './afterSale/'.date('Ym');
$return_data = DealPicService::upload($request);
if ($return_data['code'] == 200) {
return response()->json(['ErrorCode' => 1, 'ErrorMessage' => '上传成功', 'Data' => $return_data['data']]);
} else {
return response()->json(['ErrorCode' => 2, 'ErrorMessage' => $return_data['msg'], 'Data' => '']);
}
}
/**
* 详情
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param Request $request [description]
* @return [type] [description]
*/
public function info (Request $request) {
// 验证数据
$error_message = $this->dataValidator->infoValidator($request->all());
if ($error_message) {
return response()->json(['ErrorCode'=>ErrorInc::INVALID_PARAM, 'ErrorMessage'=>$error_message->first(), 'Data'=>[$error_message]]);
}
$data = $request->all();
$data['ip'] = $request->ip();
$return_data = AftersaleOrderService::info($data);
return response()->json($return_data);
}
}
......@@ -25,10 +25,11 @@ class TipsController extends BaseController
*/
public function index(Request $request){
if($admin_pt_id = $request->get('session_token')['admin_groupnew'] == 2){
$orderList = OrderList::where('stauas',20)->where('ser_id',$request->get('session_token')['id'])->count();
$orderList = OrderList::where('stauas',20)->where('ser_id',$request->get('session_token')['id'])->get();
if(!empty($orderList)) {
$list[0]['msg'] = "您有新工单未领取";
$list[0]['count'] = $orderList;
$list[0]['count'] = count($orderList);
$list[0]['orderList'] = $orderList;
$list[0]['url'] = 'Ordersystem/OrderList';
}else{
$list = [];
......
......@@ -51,6 +51,8 @@ use App\Services\SettlementThreeService;
use App\Services\SysStoresService;
use App\Services\TicketListService;
use App\Services\UserService;
use App\Services\OrderDeductionFeeService;
use App\Services\WarehouseService;
use BlueCity\Core\Inc\ErrorInc;
use BlueCity\Data\Service\ZhiPei\OrderService as zhiPeiOrder;
use DB;
......@@ -148,8 +150,16 @@ class OrderListController extends BaseController
//$ansql = "p_id in (".$session_token['admin_pt_id'].")";
}
if($session_token['admin_groupnew']!=7){
$where .= ' and company_id='.$session_token['company_id'];
// if($session_token['admin_groupnew']!=7){
// $where .= ' and company_id='.$session_token['company_id'];
// }
if (!in_array($session_token['admin_groupnew'], [2,3,7])){//管理员可以看全部
$where.=" and company_id='".$session_token['company_id']."'";
}
if ($session_token['admin_groupnew'] == 3) {
$where.=" and agency_id='".$session_token['company_id']."'";
// $where['gone_order_list.agency_id'] = $session['company_id'];
}
//统计数量
......@@ -1725,7 +1735,7 @@ class OrderListController extends BaseController
$orderListArr = OrderListService::getOrderListByID($id);
if(!$orderListArr){
return $this->error('无此单', ErrorInc::MYSQL_FAILED, []);exit;
return $this->error('无此单', ErrorInc::MYSQL_FAILED, []);exit;
}
$goodid = OrderMsg::where('id',$orderListArr['order_goods_id'])->value('goods_id');
......@@ -1821,7 +1831,36 @@ class OrderListController extends BaseController
exit;
}
}
// 扣费
$post_data['adm_id'] = $orderListArr['admin_id'];
$post_data['company_id'] = $orderListArr['company_id'];
$post_data['order_number'] = $orderListArr['sys_num'];
$post_data['reo_price'] = -0.5;
$reduce_price = OrderDeductionFeeService::deductFee($post_data);
// 扣库存
$ware_id = DB::table('warehouse')
->where('company_id', $orderListArr['agency_id'])
->value('id');
if (empty($ware_id)) {
// 新增默认仓库
$add_ware['shck_ckmc'] = '默认仓库';
$add_ware['company_id'] = $company_id;
$ware_id = DB::table('warehouse')->insertGetId($add_ware);
}
$warehouse_data['ware_id'] = $ware_id;
$warehouse_data['sys_num'] = $orderListArr['sys_num'];
$warehouse_data['serial_number'] = $orderListArr['serial_number'];
$find_goods_data = DB::table('order_msg')
->where('id', $orderListArr['order_goods_id'])
->get();
if ($find_goods_data) {
foreach ($find_goods_data as $key => $value) {
$goods_data[$key]['goods_num'] = 0-$value['goods_num'];
$goods_data[$key]['goods_id'] = $value['goods_id'];
}
$warehouse_data['goods_data'] = $goods_data;
$reduce_wago_res = WarehouseService::chargeWareGoodsNum($warehouse_data);
}
if ($request->input('fahuo_type')==1 || $request->input('stats1')==1){
Management::where('trace_code',$orderListArr['serial_number'])->update($info);// 追溯
$ret = $this->feedbackOne($orderListArr, $input, $admin_acc, $company);
......
......@@ -265,6 +265,18 @@ class PayController extends BaseController
$notify_url = 'http://jdh.bluearp.com/index.php/api/service/Pay/notify';
$timestamp = time();
$wepay_res = WashPayservice::createJsBizPackage($total_fee, $out_trade_no, $body, $notify_url, $timestamp, $config);
// 新增在线支付记录
$were_add_data['were_company_id'] = $find_order['reo_company_id']; //所属公司id
$were_add_data['were_admin_id'] = $find_order['reo_adm_id']; //客户单位id,会员id
$were_add_data['were_type'] = 1;
$were_add_data['out_trade_no'] = $find_order['reo_order_number']; //商户订单号
$were_add_data['were_description'] = '充值-'.$find_order['reo_price'].'元'; //商品描述
$were_add_data['were_pay_total_money'] = $find_order['reo_price']; //支付总金额(单位分)
$were_add_data['were_pay_way'] = 1; //在线支付方式1微信小程序支付
$were_add_data['were_pay_type'] = 1; //在线支付类型1付款2退款
$were_add_data['were_create_time'] = date('Y-m-d H:i:s');
$were_add_data_res = DB::table('weixin_record')->insert($were_add_data);
return response()->json($wepay_res);
}
......@@ -353,6 +365,17 @@ class PayController extends BaseController
$result = $aliPay->aliPay();
$result = $result['alipay_trade_precreate_response'];
if($result['code'] && $result['code']=='10000'){
// 新增在线支付记录
$were_add_data['were_company_id'] = $find_order['reo_company_id']; //所属公司id
$were_add_data['were_admin_id'] = $find_order['reo_adm_id']; //客户单位id,会员id
$were_add_data['were_type'] = 1;
$were_add_data['out_trade_no'] = $find_order['reo_order_number']; //商户订单号
$were_add_data['were_description'] = '充值-'.$find_order['reo_price'].'元'; //商品描述
$were_add_data['were_pay_total_money'] = $find_order['reo_price']; //支付总金额(单位分)
$were_add_data['were_pay_way'] = 2; //在线支付方式1微信小程序支付
$were_add_data['were_pay_type'] = 1; //在线支付类型1付款2退款
$were_add_data['were_create_time'] = date('Y-m-d H:i:s');
$were_add_data_res = DB::table('weixin_record')->insert($were_add_data);
//这里处理你的业务逻辑,如生成订单
// return $result['qr_code'];//这里是支付宝返回的付款url,需要返回到页面生成二维码
return response()->json(['code'=>200, 'msg'=>'success', 'data'=>$result['qr_code']]);
......@@ -368,16 +391,19 @@ class PayController extends BaseController
CommonService::addLog('支付回调:', json_encode($data,true), 1, 'aliPayNotify');
if ($request['trade_status'] == 'TRADE_SUCCESS') {
$find_order = DB::table('recharge_order')
->where('reo_order_number', $postObj->out_trade_no)
->where('reo_order_number', $request['out_trade_no'])
->first();
if ($find_order->reo_pay_state == 1) {
if ($find_order['reo_pay_state'] == 1) {
echo "success"; //请不要修改或删除
die;
}
$update_were = DB::table('weixin_record')
->where('out_trade_no', $request['out_trade_no'])
->update(['were_pay_state'=>2,'were_transaction_id'=>$request['trade_no']]);
$update_order = DB::table('recharge_order')
->where('reo_order_number', $postObj->out_trade_no)
->update(['reo_pay_state'=>2,'reo_paid_money'=>$find_order->reo_price,'reo_pay_way'=>1,'reo_pay_check'=>1, 'reo_pay_time'=>date('Y-m-d H:i:s')]);
->where('reo_order_number', $request['out_trade_no'])
->update(['reo_pay_state'=>2,'reo_paid_money'=>$find_order['reo_price'],'reo_pay_way'=>2,'reo_pay_check'=>1, 'reo_pay_time'=>date('Y-m-d H:i:s')]);
$find_data = DB::table('admin_recharge')
->where('adre_company_id', $find_order['reo_company_id'])
->first();
......@@ -389,9 +415,8 @@ class PayController extends BaseController
}
$find_data['find_order'] = $find_order;
$find_data['shop_update'] = $shop_update;
$find_data['find_shop'] = $find_shop;
Common::write_log($find_data, 1, 'aliPayNotify1');
$find_data['update_order'] = $update_order;
CommonService::addLog('支付回调:', json_encode($find_data,true), 1, 'aliPayNotify');
echo "success"; //请不要修改或删除
} elseif($request['trade_status'] == 'TRADE_FINISHED') {
//判断该笔订单是否在商户网站中已经做过处理
......
......@@ -531,7 +531,7 @@ class ServiceProviderController extends BaseController
}
$session = $request->get('session_token');
//保存主要信息
$adminData = $request->only(['enable', 'company_name', 'is_lidao', 'admin_name', 'admin_acc', 'type','brand_service','service_type']);
$adminData = $request->only(['enable', 'company_name', 'is_lidao', 'admin_name', 'admin_acc', 'type','brand_service','service_type', 'admin_groupnew']);
$admin_acc = Admin::where("admin_acc",$adminData['admin_acc'])->where("company_id",$session['company_id'])->first();
if($admin_acc){
return $this->error('账户名已存在', ErrorInc::INVALID_PARAM);
......@@ -543,6 +543,23 @@ class ServiceProviderController extends BaseController
// $adminData = $request->only(array_keys($this->validateRules['rules']));
$adminData = $this->_setAdminData($adminData, $request);
$adminData['company_id'] = $session['company_id'];
if ($adminData['admin_groupnew'] == 3) {//经销商新增一个公司
$adminData['admin_groupnew'] = 3;
$com_data['com_type'] = 2;
$com_data['com_name'] = $data['service_name'];
$com_data['com_phone'] = $data['phone'];
$com_data['com_start_time'] = date('Y-m-d H:i:s');
$com_data['com_create_time'] = date('Y-m-d H:i:s');
$com_data['com_end_time'] = date('Y-m-d H:i:s', strtotime('+50 year'));
$com_data['com_admin_id'] = $session['id'];
$company_id = DB::table('company')->insertGetId($com_data);
$adminData['company_id'] = $company_id;
// 新增默认仓库
$add_ware['shck_ckmc'] = '默认仓库';
$add_ware['company_id'] = $company_id;
$ware_id = DB::table('warehouse')->insertGetId($add_ware);
}
$adminID = AdminService::insertData($adminData);
if ($adminID) {
//保存资料信息
......@@ -638,11 +655,10 @@ class ServiceProviderController extends BaseController
private function _setAdminData($adminData, Request $request)
{
$adminData['admin_password'] = md5($request->input('admin_password'));//密码
$adminData['admin_groupnew'] = $request->input('admin_groupnew',2);//服务
$adminData['admin_groupnew'] = $request->input('admin_groupnew',2);//2服务商3经销
$adminData['mouth_pay'] = $request->input('mouth_pay', 1);//结算状态
$adminData['unified'] = $request->input('unified', 1);//价格状态
$adminData['reward'] = $request->input('reward', 1);//奖惩设置
$adminData['admin_groupnew'] = 2;//服务商
$adminData['admin_group'] = 2;//旧版服务商
//经营品牌
......
<?php
/**
* 支付管理
*/
namespace App\Http\Controllers\Service;
use App\Http\Controllers\BaseController;
use App\Http\Controllers\Common\CommonController;
use App\Services\WashPayservice;
use App\Services\PayService;
use BlueCity\Core\Inc\ErrorInc;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Maatwebsite\Excel\Facades\Excel;
use BlueCity\Core\Sdk\MiscSapi;
use Illuminate\Support\Facades\DB;
use App\Services\CommonService;
use App\Models\Warehouse;
use App\Services\BmmcService;
class WarehouseController extends BaseController
{
public function __construct()
{
// $service = new ServiceProviderService();
$this->bootWithService($service);
}
/**
* 仓库列表
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-06
* @param Request $request [description]
* @return [type] [description]
*/
public function index(Request $request) {
$session = Request()->get('session_token');//用户信息
$Db = new Warehouse();
if($request->filled('shck_ckmc')){ //仓库名称
$shck_ckmc = $request->input('shck_ckmc');
$Db = $Db->where('shck_ckmc', 'like','%'.$shck_ckmc.'%');
}
$page_size = $request->input('page_size',10);
$page = $request->input('page',1);
if ($session['admin_groupnew'] != 7) {
$Db = $Db->where('company_id', $session['company_id']);
}
if($page<1){
$page = 1;
}
$paginate = $Db->orderBy('id','DESC')->paginate($page_size);
$list = self::dataToArray($paginate->items());
$all_button = BmmcService::whereButton($request->input('token'),$request->input('Pri_id'));
$data['button_top'] = $export['button_top']??[];//顶部按钮
$data['button_search'] = $export['button_search']??[];//搜索栏按钮
if (empty($list)) {
// 新增默认仓库
$add_ware['shck_ckmc'] = '默认仓库';
$add_ware['company_id'] = $session['company_id'];
$ware_id = DB::table('warehouse')->insertGetId($add_ware);
}
$paginate = $Db->orderBy('id','DESC')->paginate($page_size);
$list = self::dataToArray($paginate->items());
if($list){
foreach ($list as $k =>$v){
$list[$k]['ware_goods_num'] = DB::table('ware_goods')
->where('wago_ware_id', $v['id'])
->sum('wago_stock_num');
$button = ['wareGoods', 'addGoodsNum'];
$button = BmmcService::getListButton($button,$all_button);
$list[$k]['button_one'] = $button['button_one']??[];
$list[$k]['button_two'] = $button['button_two']??[];
$list[$k]['button_three'] = $button['button_three']??[];
}
$data['list'] = $list;
$data['page'] = [
'count' => $paginate->total(),
'page'=>$paginate->currentPage(),
'page_size'=>$page_size,
'allPage'=>$paginate->lastPage()
];
return $this->success('获取成功', $data);
}else{
return $this->error('暂无数据', ErrorInc::DATA_EMPTY,$data);
}
}
/**
* 增加库存
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-09
* @param Request $request [description]
*/
public function addGoodsNum(Request $request) {
if (empty($request['ware_id'])) {
return response()->json(['Data' =>'', 'ErrorMessage' => '请选择仓库', 'ErrorCode' => 2]);
}
if (empty($request['goods_id'])) {
return response()->json(['Data' =>'', 'ErrorMessage' => '请选择商品', 'ErrorCode' => 2]);
}
if (empty($request['goods_num'])) {
return response()->json(['Data' =>'', 'ErrorMessage' => '请选择数量', 'ErrorCode' => 2]);
}
$find_goods = DB::table('pj_goods')
->where('pg_id', $request['goods_id'])
->first();
if (empty($find_goods)) {
return response()->json(['Data' =>'', 'ErrorMessage' => '未查询到此商品', 'ErrorCode' => 2]);
}
if ($find_goods['is_delect'] == 2) {
return response()->json(['Data' =>'', 'ErrorMessage' => '此商品已停用', 'ErrorCode' => 2]);
}
$find_data = DB::table('ware_goods')
->where('wago_ware_id', $request['ware_id'])
->where('wago_goo_id', $request['goods_id'])
->first();
DB::beginTransaction();
if (empty($find_data)) {
$add_data['wago_company_id'] = $session['company_id'];
$add_data['wago_ware_id'] = $request['ware_id'];
$add_data['wago_goo_id'] = $request['goods_id'];
$add_data['wago_stock_num'] = $request['goods_num'];
$add_res = DB::table('ware_goods')->insertGetId($add_data);
} else {
$update['wago_stock_num'] = $find_data['wago_stock_num'] + $request['goods_num'];
$add_res = DB::table('ware_goods')
->where('wago_id', $find_data['wago_id'])
->update($update);
$add_res = $find_data['wago_id'];
}
$add_record['goio_ware_id'] = $request['ware_id'];
$add_record['goio_wago_id'] = $add_res;
$add_record['goio_goo_id'] = $request['goods_id'];
$add_record['goio_num'] = $request['goods_num'];
$add_record['goio_type'] = '增加库存';
$add_record_res = DB::table('goods_inout')->insert($add_record);
if ($add_res && $add_record_res) {
DB::commit();
return response()->json(['Data' =>'', 'ErrorMessage' => '成功', 'ErrorCode' => 1]);
} else {
DB::rollback();
return response()->json(['Data' =>'', 'ErrorMessage' => '失败', 'ErrorCode' => 2]);
}
}
/**
* 仓库商品列表
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-10
* @param Request $request [description]
* @return [type] [description]
*/
public function wareGoods(Request $request) {
$session = Request()->get('session_token');//用户信息
$page_size = $request->input('page_size',10);
$page = $request->input('page',1);
$paginate = DB::table('ware_goods')
->leftjoin('pj_goods','pg_id', '=', 'wago_goo_id')
->where('wago_ware_id', $request['ware_id'])
->select('ware_goods.*', 'pj_goods.pg_goodsname', 'brand_name', 'pg_series')
->paginate($page_size);
$list = $paginate->items();
if($list){
foreach ($list as $k =>$v){
$list[$k]['ware_goods_num'] = DB::table('ware_goods')
->where('wago_ware_id', $v['id'])
->sum('wago_stock_num');
$button = [];
$button = BmmcService::getListButton($button,$all_button);
$list[$k]['button_one'] = $button['button_one']??[];
$list[$k]['button_two'] = $button['button_two']??[];
$list[$k]['button_three'] = $button['button_three']??[];
}
$data['list'] = $list;
$data['page'] = [
'count' => $paginate->total(),
'page'=>$paginate->currentPage(),
'page_size'=>$page_size,
'allPage'=>$paginate->lastPage()
];
return $this->success('获取成功', $data);
}else{
return $this->error('暂无数据', ErrorInc::DATA_EMPTY,$data);
}
}
/**
* 出入库记录
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-11
* @param Request $request [description]
* @return [type] [description]
*/
public function wareGoodsRecord(Request $request) {
$session = Request()->get('session_token');//用户信息
$page_size = $request->input('page_size',10);
$page = $request->input('page',1);
$paginate = DB::table('goods_inout as g')
->leftjoin('pj_goods as p', 'p.pg_id', '=', 'g.goio_goo_id')
->leftjoin('warehouse as w', 'g.goio_ware_id', '=', 'w.id')
->leftjoin('company as c','c.com_id', '=', 'w.company_id')
->where('com_id', $session['company_id'])
->select('shck_ckmc', 'pg_goodsname', 'goio_num', 'goio_type', 'goio_sys_num', 'goio_serial_number', 'goio_old_num', 'goio_new_num')
->paginate($page_size);
$list = $paginate->items();
if($list){
foreach ($list as $k =>$v){
if (empty($v['goio_sys_num'])) {
$list[$k]['goio_sys_num'] = '--';
}
if (empty($v['goio_serial_number'])) {
$list[$k]['goio_serial_number'] = '--';
}
// $button = [];
// $button = BmmcService::getListButton($button,$all_button);
// $list[$k]['button_one'] = $button['button_one']??[];
// $list[$k]['button_two'] = $button['button_two']??[];
// $list[$k]['button_three'] = $button['button_three']??[];
}
$data['list'] = $list;
$data['page'] = [
'count' => $paginate->total(),
'page'=>$paginate->currentPage(),
'page_size'=>$page_size,
'allPage'=>$paginate->lastPage()
];
return $this->success('获取成功', $data);
}else{
return $this->error('暂无数据', ErrorInc::DATA_EMPTY,$data);
}
}
}
<?php
namespace App\Http\Requests\Validators\Api\MobileWeb;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Validator;
// 移动端-售后单列表
class AftersaleOrderValidator extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
// 列表验证器
public function indexValidator($data)
{
// 自定义错误消息
$messages = [
'status.required' => '请输入售后单状态',
'status.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'status' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 详情验证器
public function handle_iveValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请选择售后单id',
'id.integer' => '参数错误',
'quality_content.required' => '请输入处理内容',
'quality_content.max' => '参数错误',
'appoint_time.required' => '请选择预约时间',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'quality_content' => 'required|string|max:50',
'appoint_time' => 'required',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 日常反馈验证器
public function dailyFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请选择售后单id',
'id.integer' => '参数错误',
'remark.required' => '请输入反馈内容',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'remark' => 'required',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 列表验证器
public function infoValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请输入售后单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 接单验证器入口
public function receivingStartValidator($data)
{
// 自定义错误消息
$messages = [
'type.required' => '请输入请求类型',
'type.in' => '参数错误',
'id.required' => '请输入工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'type' => [//类型1强制登录2不登录
'required',
Rule::in(['1', '2']),
],
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 接单验证器
public function receivingValidator($data)
{
// 自定义错误消息
$messages = [
'receive_install_id.required' => '请选择安装人员',
'receive_install_id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'receive_install_id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 拒单验证器
public function refuseValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
'stauas.required' => '订单状态错误',
'stauas.integer' => '参数错误',
'refuseType.required' => '未选择拒单方式',
'refuseType.integer' => '参数错误',
'remarks.required' => '请输入拒单备注',
'remarks.max' => '拒单备注长度超出限制',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'stauas' => 'required|integer|min:1',
'refuseType' => 'required|integer|min:1',
'remarks' => 'required|string|max:255',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 预约验证器
public function contactValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
'day_time.required' => '请填写预约时间',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'day_time' => 'required|string|max:255',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 开始安装验证器
public function startInstallValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 安装反馈验证器
public function installFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'id.required' => '请输入服务工单id',
'type.required' => '请选择完成类型',
// 'template_data.required' => '请输入图片相关数据',
// 'license_plate.required' => '请输入车牌号',
// 'license_plate.max' => '长度超出限制',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
'type' => 'required|integer|min:1',
// 'template_data' => 'required',
// 'license_plate' => 'required|string|max:20',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 操作记录验证器
public function operatingRecordValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'serial_number.required' => '请输入单号',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'serial_number' => 'required',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 反馈安装图片验证器
public function imageFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'image_url.required' => '参数错误',
'image_id.required' => '参数错误',
'image_type.required' => '参数错误',
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'image_url' => 'required|min:1',
'image_type' => 'required|min:1',
'image_id' => 'required|min:1',
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 反馈车牌车架号验证器
public function LicenseFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'gd_id.required' => '参数错误',
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'gd_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
}
<?php
namespace App\Http\Requests\Validators\Api\MobileWeb;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Validator;
// 移动端-账单列表
class StatementsListValidator extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
// 列表验证器
public function indexValidator($data)
{
// 自定义错误消息
$messages = [
'status.required' => '请输入账单状态',
'status.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'status' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 详情验证器
public function handle_iveValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请选择售后单id',
'id.integer' => '参数错误',
'quality_content.required' => '请输入处理内容',
'quality_content.max' => '参数错误',
'appoint_time.required' => '请选择预约时间',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'quality_content' => 'required|string|max:50',
'appoint_time' => 'required',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 日常反馈验证器
public function dailyFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请选择售后单id',
'id.integer' => '参数错误',
'remark.required' => '请输入反馈内容',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'remark' => 'required',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 列表验证器
public function infoValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请输入售后单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 接单验证器入口
public function receivingStartValidator($data)
{
// 自定义错误消息
$messages = [
'type.required' => '请输入请求类型',
'type.in' => '参数错误',
'id.required' => '请输入工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'type' => [//类型1强制登录2不登录
'required',
Rule::in(['1', '2']),
],
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 接单验证器
public function receivingValidator($data)
{
// 自定义错误消息
$messages = [
'receive_install_id.required' => '请选择安装人员',
'receive_install_id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'receive_install_id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 拒单验证器
public function refuseValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
'stauas.required' => '订单状态错误',
'stauas.integer' => '参数错误',
'refuseType.required' => '未选择拒单方式',
'refuseType.integer' => '参数错误',
'remarks.required' => '请输入拒单备注',
'remarks.max' => '拒单备注长度超出限制',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'stauas' => 'required|integer|min:1',
'refuseType' => 'required|integer|min:1',
'remarks' => 'required|string|max:255',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 预约验证器
public function contactValidator($data)
{
// 自定义错误消息
$messages = [
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
'day_time.required' => '请填写预约时间',
];
// 数据验证
$validator = Validator::make($data, [
'id' => 'required|integer|min:1',
'day_time' => 'required|string|max:255',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 开始安装验证器
public function startInstallValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 安装反馈验证器
public function installFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'id.required' => '请输入服务工单id',
'type.required' => '请选择完成类型',
// 'template_data.required' => '请输入图片相关数据',
// 'license_plate.required' => '请输入车牌号',
// 'license_plate.max' => '长度超出限制',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
'type' => 'required|integer|min:1',
// 'template_data' => 'required',
// 'license_plate' => 'required|string|max:20',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 操作记录验证器
public function operatingRecordValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'serial_number.required' => '请输入单号',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'serial_number' => 'required',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 反馈安装图片验证器
public function imageFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'image_url.required' => '参数错误',
'image_id.required' => '参数错误',
'image_type.required' => '参数错误',
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'image_url' => 'required|min:1',
'image_type' => 'required|min:1',
'image_id' => 'required|min:1',
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
// 反馈车牌车架号验证器
public function LicenseFeedbackValidator($data)
{
// 自定义错误消息
$messages = [
'install_id.required' => '参数错误',
'admin_id.required' => '参数错误',
'gd_id.required' => '参数错误',
'id.required' => '请输入服务工单id',
'id.integer' => '参数错误',
];
// 数据验证
$validator = Validator::make($data, [
'install_id' => 'required|integer|min:1',
'admin_id' => 'required|integer|min:1',
'gd_id' => 'required|integer|min:1',
'id' => 'required|integer|min:1',
], $messages);
// 判断数据验证是否成功
if ($validator->fails()) {
return $validator->errors();
}
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RechargeOrder extends Model
{
protected $table ='recharge_order';
protected $guarded = [];
public $timestamps=false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Warehouse extends Model
{
protected $table ='warehouse';
protected $guarded = [];
public $timestamps=false;
}
<?php
namespace App\Services\Api\MobileWeb;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;
use BlueCity\Core\Inc\ErrorInc;
use App\Models\{Admin,
GhPrice,
GoodsBrand,
InstallLine,
Management,
Note,
OrderList,
OrderMsg,
OrderRejected,
Orders,
InstallPerson,
OrderTime,
SetmoneyType,
SettlementList,
SettlementMoney,
SubmitPlease,
User,
OrderAfter
};
use App\Services\{BmmcService, Api\OrderManage\OrdersVehicleService, CommonService};
class AftersaleOrderService extends Model
{
/**
* 售后列表
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $request [description]
* @param integer $show_count [description]
* @return [type] [description]
*/
public static function index($request, $show_count = 10)
{
$session = $request['session'];
// 查询列表
$list_data = DB::table('order_after as o');
$where['ser_id'] =$session['admin_id'];//服务商id
if (!empty($session['install_id']) && $session['user_type'] == 1) {
$where['intall_id'] =$session['install_id'];//技师id
}
if (!empty($request['status'])) {
if($request['status'] == 1){
// 未处理
$wheres['status_searchin'] = [1];
}elseif($request['status'] == 2){
// 处理中
$wheres['status_searchin'] = [10,15];
}elseif($request['status']==3){
// 审核中
$wheres['status'] = 30;
}elseif($request['status']==4){
// 已完成
$wheres['status_searchin'] = [40];
}
}
$wheres = array_merge($where, $wheres);
$wheres = CommonService::jointWhere($wheres);
$list_data = $list_data->whereRaw($wheres)
->select('id', 'after_num', 'shr_id', 'shr_name', 'shr_phone', 'shr_address', 'shr_sheng', 'shr_shi','shr_xian', 'good_names', 'create_time', 'deal_sertime', 'finish_time', 'status', 'day_time');
$list_data = $list_data->orderby('id', 'desc');
$list_data = $list_data->paginate($show_count);
$page['count'] = 0;
$page['page'] = 0;
$page['page_size'] = $show_count;
$page['allPage'] = 0;
$data['list'] = [];
$data['page'] = $page;
// 'negotiated_price as orli_actual_price' 服务费
$list_items = $list_data->items();
if ($list_items) {
$list_items = CommonService::dataToArray($list_items);
$getStauasName = self::getStauasName();
foreach ($list_items as $key => $value) {
$list_items[$key]['stauasName'] = $getStauasName[$value['status']]['name'];
// // 获取第一个字符
// if(in_array($value['stauas'],[10,20])){
// $list_items[$key]['shr_phone'] = substr_replace($list_items[$key]['shr_phone'], '****', 3, 4);
// }
$mb_first = mb_substr($value['shr_name'], 0, 1, 'utf-8');
$list_items[$key]['first_name'] = $mb_first;
$list_items[$key]['day_time'] = empty($value['day_time']) ? '--':$value['day_time'];
$list_items[$key]['button'] = [];
if(in_array($value['status'],[1])){
$list_items[$key]['button'] = [['action'=>'handle_ive','name'=>'立即处理']];
}
if(in_array($value['status'],[10])){
$list_items[$key]['button'] = [['action'=>'quality','name'=>'申请完成'],['action'=>'dailyFeedback','name'=>'日常反馈']];
}
}
$page['count'] = $list_data->total(); //总数据个数
$page['page'] = $list_data->currentPage(); //当前页面页码
$page['page_size'] = $show_count; //一页显示多少个
$page['allPage'] = $list_data->lastPage(); //表示最后一页的页码
$data['list'] = $list_items;
$data['page'] = $page;
}
// 查询接单的状态统计数据,改为用上面查询出来的组装就行,因为数据格式完全变了,从订单表查了,所以根据上面的状态就可以获取数量了
$where['status_searchin'] = [1,10,15,30,40];
$where = CommonService::jointWhere($where);
$data_num = DB::table('order_after')->whereRaw($where)->groupBy('status')->select('status',DB::raw('count(*) as total'))->get();
$wcl_num = 0;
$clz_num = 0;
$shz_num = 0;
$ywc_num = 0;
if($data_num){
$data_num = CommonService::dataToArray($data_num);
foreach($data_num as $k => $v){
switch ( $v['status'] ){
case 1:
$wcl_num = $wcl_num + $v['total'];
break;
case 10:
$clz_num = $clz_num + $v['total'];
break;
case 15:
$clz_num = $clz_num + $v['total'];
break;
case 30:
$shz_num = $shz_num + $v['total'];
break;
case 40:
$ywc_num = $ywc_num + $v['total'];
break;
default:
;
break;
}
}
}
$status_count=[];
$status_count[] = ['count'=>$wcl_num,'status'=>1];
$status_count[] = ['count'=>$clz_num,'status'=>2];
$status_count[] = ['count'=>$shz_num,'status'=>3];
$status_count[] = ['count'=>$ywc_num,'status'=>4];
$data['status_count'] = $status_count;
if ($data['list']) {
return ['ErrorCode' => 1, 'ErrorMessage' => '成功', 'Data' => $data];
} else {
return ['ErrorCode' => 1, 'ErrorMessage' => '暂无数据', 'Data' => $data];
}
}
/**|---------------------------------------------------------------------------------
* @name 立即处理
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* |---------------------------------------------------------------------------------
*/
public static function handle_ive ($request)
{
DB::beginTransaction();
$session = $request['session'];
$find_data = DB::table('order_after')
->where('id', $request['id'])
->first();
$order_num = $find_data['order_num'];
$status = $find_data['status'];
if ($status !=1){
return ['ErrorCode' => 2, 'ErrorMessage' => '售后状态不正确', 'Data' => ''];
}
$feek_time = date('Y-m-d',strtotime("+1day")).' 17:30:00'; //明天下午5:30时间
$info['feek_time'] = $feek_time;
$info['status'] = 10; //改为处理中
$info['day_time'] = $request['appoint_time'];
$res = OrderAfter::where('id',$request['id'])->update($info);
if ($res){
$rest = CommonService::accMe($find_data['sys_num'],'售后列表',$request['quality_content'],$find_data['sys_num'],2,2,$session['install_name'],$session['install_id']);
if ($rest){
CommonService::inserting_log('售后列表',$find_data['sys_num'],'售后处理','售后列表',$session,$request['ip']);//日志
//修改领取人
$get_id = OrderAfter::where('id',$request['id'])->value('get_id');
if(!$get_id){
OrderAfter::where('id',$request['id'])->update(['get_id'=>$session['id'],'get_time'=>date("Y-m-d H:i:s")]);
}
DB::commit();
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
/**
* 日常反馈
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $data [description]
* @return [type] [description]
*/
public static function dailyFeedback($request) {
$session = $request['session'];
$find_data = DB::table('order_after')
->where('id', $request['id'])
->first();
DB::beginTransaction();
$rest = CommonService::accMe($find_data['sys_num'],'售后列表',$request['remark'],$find_data['sys_num'],2,2,$session['install_name'],$session['install_id']);
if ($rest){
CommonService::inserting_log('售后列表',$find_data['sys_num'],'日常反馈','售后列表',$session,$request['ip']);//日志
DB::commit();
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
/**
* 详情
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $data [description]
* @return [type] [description]
*/
public static function info($data) {
$session = $data['session'];
$find_data = DB::table('order_after')
->where('id', $data['id'])
->select('id', 'after_num', 'shr_id', 'shr_name', 'shr_phone', 'shr_address', 'shr_sheng', 'shr_shi','shr_xian', 'good_names', 'create_time', 'deal_sertime', 'finish_time', 'status', 'sys_num', 'day_time', 'serial_number')
->first();
$remark = CommonService::orderRemarks($find_data['sys_num'],'',2,$session['install_id']);
$image = DB::table('feedsales')
->where('gl_id', $find_data['id'])
->where('sys_num', $find_data['sys_num'])
->get();
if(in_array($find_data['status'],[1])){
$find_data['button'] = [['action'=>'handle_ive','name'=>'立即处理']];
}
if(in_array($find_data['status'],[10])){
$find_data['button'] = [['action'=>'quality','name'=>'申请完成'],['action'=>'dailyFeedback','name'=>'日常反馈']];
}
$return_data['data'] = $find_data;
$return_data['remark'] = $remark ? $remark : [];
$return_data['image'] = $image;
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => $return_data];
}
/**
* 申请完成
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $data [description]
* @return [type] [description]
*/
public static function quality($data) {
$session = $data('session');
$find_data = OrderAfter::where('id',$data['id'])->first();
$serial_number = $find_data['serial_number'];
if($find_data['status']==1 || $find_data['status']==10 || $find_data['status']==15){
}else{
return ['ErrorCode' => 2, 'ErrorMessage' => '售后状态错误', 'Data' => []];
}
Db::beginTransaction();
$rest = CommonService::accMe($find_data['sys_num'],"售后订单","【售后】申请完成,".$data['quality_content'],$serial_number,'2',$session['admin_groupnew'],$session['admin_acc'],$session['id']);
if($rest){
if ($data['file'] && $data['file'] != []){
$company_name = Admin::where('id',$find_data['deal_serid'])->value("company_name");
$inst = InstallPerson::where('admin_id',$find_data['deal_serid'])->first();//安装人员
$sql = 'INSERT INTO gone_feedsales (`type`,`gl_id`,`install_name`,`install_phone`,`install_time`,`admin_id`,`company_name`,`feedback_status`,`sys_num`,`is_type`,`feedback_pic`) VALUES';
$num = 0;
foreach($data['file'] as $key=>$val){
$num = $num + 1;
$sql .= "('".$num."','".$data['id']."','".$inst['install_name']."','".$inst['install_phone']."','".date("Y-m-d H:i:s")."','".$find_data['deal_serid']."','".$company_name."','2','".$find_data['after_num']."','2','".$val."'),";
}
$sql = substr($sql,0,strlen($sql) - 1);
DB::insert($sql);
}
$get['deal_time'] = date("Y-m-d H:i:s");
$get['status'] = '30';
$get['trigyn'] = '1';
if($Olaf['get_id'] < 1){
$get['get_id'] = $session['id'];
$get['get_time'] = date("Y-m-d H:i:s");
}
$result = OrderAfter::where('id',$Input['id'])->update($get);
if($result){
$after_num = OrderAfter::where('id',$Input['id'])->select('after_num','p_id')->first();
$get['after_num'] = $after_num['after_num'];
DB::commit();
$this->operatingTime($Input['sys_num'],'申请质保完成时间',date("Y-m-d H:i:s"),$Olaf['order_num'],$session['admin_acc']);//订单操作时间
$this->insertingLog("申请质保完成,",$Input['sys_num'],"订单(".$serial_number.")","派工单列表",$request->ip(),$session['admin_acc']);//日志
return $this->success('操作成功');exit;
}else{
DB::rollBack();
return $this->error('操作失败', ErrorInc::MYSQL_FAILED);exit; }
}else{
DB::rollBack();
return $this->error('添加备注失败', ErrorInc::MYSQL_FAILED);exit;
}
}
/**|---------------------------------------------------------------------------------
* @name 获取接单技师
* @param int $request 请求参数
* @param int $old_install_id 老技师id
* @retrun \Illuminate\Http\JsonResponse
* @author dou 2024/9/10 16:36
* |---------------------------------------------------------------------------------
*/
public static function getPerson ( $request , $old_install_id = 0 ){
$session = $request['session'];
$order_list = OrderList::where('id',$request['id'])->select('ser_id','customer_id')->first();
if($order_list){
$dress = User::where('id',$order_list['customer_id'])->select('shr_sheng','shr_shi','shr_xian','shr_adress')->first();
$end = CommonService::jingwei($dress['shr_sheng'], $dress['shr_sheng'].$dress['shr_shi'].$dress['shr_xian'].$dress['shr_adress']);
if(empty($old_install_id)) {
$list = InstallPerson::where('install_is_type',1)
->where('delet_y',1)
->where('admin_id',$session['admin_id'])
->select('id','install_name','longitude','latitude','install_province','install_city','install_cuntry','install_address')
->get();
}else{
$list = InstallPerson::where('install_is_type',1)
->where('delet_y',1)
->where('admin_id',$session['admin_id'])
->where('id','!=',$old_install_id)
->select('id','install_name','longitude','latitude','install_province','install_city','install_cuntry','install_address')
->get();
}
if($list){
$list = CommonService::dataToArray($list);
foreach( $list as $kri => $vri ){
if($vri['longitude'] && $vri['latitude']){
$start = $vri['longitude'].','.$vri['latitude'];
}else{
$start = CommonService::jingwei($vri['install_province'],$vri['install_province'].$vri['install_city'].$vri['install_cuntry'].$vri['install_address']);
}
if($vri['install_address']=='' || $start ==''){
$list[$kri]['juli'] = '';
$list[$kri]['jl'] = 100000;
$lists[] = $list[$kri];
unset($list[$kri]);continue;
}else{
$jingwei[] = $start;
}
}
if(!empty($jingwei) && !empty($end)){
$jingwei = implode('|', $jingwei);
$res = CommonService::juli($jingwei,$end,2);
}else{
$res = [];
}
$num_ = 0;
foreach ($list as $k => $v) {
if (!isset($res[$num_])) {
$list[$k]['juli'] = '';
$list[$k]['jl'] = 100000;
} else {
$list[$k]['juli'] = round($res[$num_]['distance']/1000,2) . '公里';
$list[$k]['jl'] = round($res[$num_]['distance']/1000,2);
}
$num_++;
}
if(!empty($lists) && !empty($list)) {
$list = array_merge($list, $lists);
}elseif (!empty($lists)){
$list = $lists;
}
$list = CommonService::resetListKey($list);
foreach($list as $k => $v){
$num[]=$v['jl'];
if($v['jl'] == 100000){
unset($list[$k]['jl']);
}
}
array_multisort($num, SORT_NUMERIC ,SORT_ASC, $list);
return ['ErrorCode' => 1, 'ErrorMessage' => '暂无数据', 'Data' => $list];
}else{
return ['ErrorCode' => 1, 'ErrorMessage' => '无可派单技师', 'Data' => $list];
}
}else{
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未获取订单信息', 'Data' => ''];
}
}
// 接单
public static function receiving($request,$ip)
{
$session = $request['session'];
// 查询服务单表信息
$orderListArr = OrderList::where('id',$request['id'])
->where('is_delete', 1)
->first();
if(empty($orderListArr)){
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$orderListArr = CommonService::dataToArray($orderListArr);
// 判断是否派单是否锁定
if(!in_array($orderListArr['stauas'], [10,20])){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单不是待接单状态!', 'Data' => []];
}
if ($orderListArr['locklist_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法接单!', 'Data' => []];
}
$MsgArr = OrderMsg::where('id',$orderListArr['order_goods_id'])
->select("goods_id","goods_name","goods_brand","goods_price")
->first();
$goods_name = $MsgArr['goods_name'];
$goods_id = $MsgArr['goods_id'];
$goods_brands = $MsgArr['goods_brand'];
$goods_name=trim($goods_name,',');
$goods_id=trim($goods_id,',');
$instArr = InstallPerson::where('id',$request['receive_install_id'])
->select("install_name","install_phone","plate_num")
->first();
if(!$instArr){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '技师不存在!', 'Data' => []];
}
$supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
->where('ser_id',$orderListArr['ser_id'])
->orderBy('id','Desc')
->value('supply_price');
if(!$supply_price){
$supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
->where('ser_id',0)
->orderBy('id','Desc')
->value('supply_price');
if(!$supply_price){
$supply_price='0.00';
}
}
//end Dong
$arr['sys_num']=$orderListArr['sys_num']; //系统单号
$arr['order_num']=$orderListArr['order_num']; //平台单号
$arr['serial_number']=$request['id']; //关联的order_list_id
$arr['msg_id']=$orderListArr['order_goods_id']; //关联msg_id
$arr['p_id']=$orderListArr['p_id']; //平台id
$arr['list_id']=$orderListArr['serial_number']; //派工单编号
$arr['ser_id']=$orderListArr['ser_id']; //服务中心id
$arr['type']=2; //出售方式
// 上门安装
$arr['installperson']=$request['receive_install_id']; // 安装人id
$arr['intall_person']=$instArr['install_name'];// 安装人名称
$arr['intall_phone']=$instArr['install_phone'];// 安装人电话
$is_bool="到店安装";
$info['installation']=2;//安装分类(上门安装)
// 供货价
$arr['order_price']=$supply_price; //供货价
// 总金额
$all_price=$supply_price; //Dong
$arr['all_price']=$all_price;
// 结算状态
$arr['sett_status']=1;
// 工单状态
$arr['list_service_type']=30;
// 客户id
$arr['customer_id']=$orderListArr['customer_id'];
$arr['category']=$orderListArr['category'];
$arr['sel_type']=$orderListArr['orli_type'];
$arr['pay_types']=$orderListArr['pay_typel'];//支付方式
$arr['goods_brand']=$goods_brands;
// 锁定状态
$submit_stauas = SubmitPlease::where('submit_sys_num',$orderListArr['sys_num'])->where('msg_id',$orderListArr['order_goods_id'])->orderBy('id','DESC')->value('submit_stauas');
if($submit_stauas==1){
$arr['locked']=2;
}
/**追 溯**/
$times=date('Y-m-d H:i:s');
$sometime=substr(date('Y-m-d H:i:s',strtotime("$times-2 month")),0,10);//入仓时间
$info['goods_name']=$goods_name;//产品名称
$info['manufacturer']=GoodsBrand::where("brand_name",$MsgArr['goods_brand'])
->where('company_id',$orderListArr['company_id'])
->value('brand_remark');//生产厂家
$info['transport']=$sometime;//入仓时间
$info['order_time']=substr($times,0,10);//下单时间
$info['install_one']=$instArr['install_name'];//安装人
$info['replacing_time']=substr(date('Y-m-d H:i:s',strtotime('+2 year')),0,10);//建议更换时间
/**派工单**/
$post['stauas']=30;//派工单状态
$post['install_id']=$_POST['id'];//安装人id
$post['intall_person']=$instArr['install_name'];//安装人姓名
$post['intall_phone']=$instArr['install_phone'];//安装人电话
$post['goods_brand']=$goods_brands;
$post['goods_type']=3; //接单直接到安装中,略过检验 Dong
$post['get_time']=date("Y-m-d H:i:s");
/**订 单**/
$get['order_status']=30;//订单状态
$get['intall_person']=$instArr['install_name'];//安装人姓名
$get['intall_phone']=$instArr['install_phone'];//安装人电话
$returncount = OrderList::where('sys_num',$orderListArr['sys_num'])
->where('stauas',20)
->count();
DB::beginTransaction(); //开启事务
if($returncount==1){
$restOrderList = OrderList::where('id',$request['id'])->update($post);
$restOrder = Orders::where('sys_num',$orderListArr['sys_num'])->update($get);
if($restOrderList && $restOrder){
$restult=1;
}else{
$restult=0;
}
}else{
$restOrderList = OrderList::where('id',$request['id'])->update($post);
if($restOrderList){
$restult=1;
}else{
$restult=0;
}
}
$arr['company_id']=$orderListArr['company_id'];
$arr['agency_id']=$orderListArr['agency_id'];
$dou=SettlementList::insertGetId($arr);
if($restult==1 && $dou){
DB::commit();
Management::where('trace_code',$orderListArr['serial_number'])->update($info);
if($dou){
self::calculates($dou,$orderListArr,$supply_price,$supply_price,$session);//计算奖惩金额以及评分
}
$weixin['ser_id'] = $_POST['id'];
$weixin['order_num'] = $orderListArr['order_num']; //平台单号
$weixin['goods_name'] = '安装服务';//$v['goods_name'];
$weixin['serial_number'] = $orderListArr['serial_number'];
$weixin['install_type'] = 2;
CommonService::requestPost('http://zptzchat.bluearp.com/m/index.php/BindingAccount/push_order', $weixin);
//begin Dong
$company_name = Admin::where('id',$orderListArr['ser_id'])->select("admin_acc","company_name","reward")->first();//服务中心名称
$douId = SettlementList::where('list_id',$orderListArr['serial_number'])->value('id');
$res = SettlementMoney::where('sem_slid',$douId)->where('sem_type',17)->first();
if(!$res){
$payout_time = OrderTime::where("serial_number",$orderListArr['serial_number'])->where("is_type",'接单时间')->orderBy("id",'DESC')->value('create_time');//获取奖罚起始时间
$money_type = SetmoneyType::where("sety_id",'17')->pluck('sety_price','sety_id');
$zero1=time();//strtotime (date("Y-m-d H:i:s")); //当前时间 ,注意H 是24小时 h是12小时
$zero2=strtotime ($payout_time); //过年时间,不能写2014-1-21 24:00:00 这样不对
$guonian=($zero1-$zero2)/60; //60s*60min*24h
if($guonian<=17 && $company_name['reward']){
$money['sem_slid']=$douId;
$money['sem_synum']=$orderListArr['sys_num'];
$money['sem_creacter']=$company_name['admin_acc'];
$money['sem_price']=$money_type[17];
$money['sem_type']=17;
SettlementMoney::insert($money);
$all_price['all_price'] = SettlementMoney::where('sem_slid',$douId)->sum('sem_price');
SettlementList::where("id",$douId)->update($all_price);
}
}
//end Dong
$content = "订单".$is_bool."(".$orderListArr['serial_number'].")";
self::operating_time($orderListArr['serial_number'],'接单时间',date("Y-m-d H-i-s"),$orderListArr['order_num'],$session);//订单操作时间
self::add_thistory($orderListArr['serial_number'],'tih_acceptime',date("Y-m-d H:i:s"),$orderListArr['ser_id'],2,$session);//添加历史时间
CommonService::inserting_log('接单1,',$orderListArr['sys_num'],$content,'派工单',$session,$ip);//日志
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
// 拒单
public static function refuse($request,$ip)
{
$session = $request['session'];
$orderListArr = OrderList::where('id',$request['id'])->select("order_num","sys_num","stauas","ser_id","p_id","ol_dispamount","serial_number")->first();
$returncount = OrderList::where('sys_num',$orderListArr['sys_num'])->select("serial_number")->get();
$returncount = CommonService::dataToArray($returncount);
$serial_number = array_unique(array_column($returncount, 'serial_number')); //派工单号
if($orderListArr['stauas']<>10 && $orderListArr['stauas']<>20 && $orderListArr['stauas']<>30){
// 拒单失败!该单状态不正确!
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '订单状态错误请刷新后操作:检索码01', 'Data' => []];
}else{
if($orderListArr['stauas']!=$_POST['stauas']){
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '订单状态错误请刷新后操作:检索码02', 'Data' => []];
}
}
if(count($returncount) > 1 && $request['refuseType'] == 1){
// 该订单有多款商品,该工单不可拒单
return ['ErrorCode' => 201, 'ErrorMessage' => '订单包含多个商品是否全部拒单', 'Data' => []];
}
DB::beginTransaction(); //开启事务
$rest = CommonService::accMe($orderListArr['sys_num'], '派工单列表web', "拒单,".$_POST['note_content'], implode(',', $serial_number), 2, 2, $session['install_name'], $session['install_id']);
$resultOrderList = OrderList::where("sys_num",$orderListArr['sys_num'])->delete();
if($orderListArr['stauas']==30){
$settListArr = SettlementList::where("sys_num",$orderListArr['sys_num'])->where("sett_status",'>',1)->first();
if(!empty($settListArr)){
// 该单已审核
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '存在结算工单不可拒单', 'Data' => []];
}
$resultsettList = SettlementList::where("sys_num",$orderListArr['sys_num'])->delete();
}else{
$resultsettList = true;
}
$data['ser_id']=0;
$data['order_status']=10;
$resultOrder = Orders::where("sys_num",$orderListArr['sys_num'])->update($data);
if($resultOrderList && $rest && $resultsettList && $resultOrder){
DB::commit();
OrderTime::whereIn('serial_number',$serial_number)->delete();//删除工单操作时间
SettlementMoney::where('sem_synum',$orderListArr['sys_num'])->delete();//金额信息接单后生成
// M("settlement_count")->where("`cou_synum`='".$_POST['sys_num']."'")->delete();//评分信息接单后生成
DB::table('order_score')->whereIn("orsc_sernum",$serial_number)->delete();//评分信息接单后生成
Management::whereIn('trace_code',$serial_number)->delete();
CommonService::inserting_log('拒单,',$orderListArr['sys_num'],'订单('.$orderListArr['order_num'].')','派工单web',$session,$ip);//日志
self::operating_time($orderListArr['serial_number'],'拒单时间',date("Y-m-d H:i:s"),$orderListArr['order_num'],$session);//订单操作时间
OrderRejected::insert(['or_order_num'=>$orderListArr['order_num'],'or_ser_id'=>$orderListArr['ser_id'],'or_creact_time'=>date("Y-m-d H:i:s"),'or_centent'=>'门店自主拒单']);
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
/**|---------------------------------------------------------------------------------
* @name 预约安装
* @param int id 订单单号
* @param string day_time 预约是啊金
* @retrun \Illuminate\Http\JsonResponse /multitype:array
* @author dou 2024/9/11 0:36
* |---------------------------------------------------------------------------------
*/
public static function contact ( $request , $ip){
$session = $request['session'];
$orderListArr = OrderTime::where("id",$request['id'])->select("order_num","sys_num","stauas","ser_id","p_id","customer_id","serial_number","ol_dispamount")->first();
if($orderListArr['stauas'] <> 30){
// 拒单失败!该单状态不正确!
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '订单状态错误请刷新后操作:检索码01', 'Data' => []];
}
$data['day_time']=$request['delay_time'];
$res = Orders::where("sys_num",$orderListArr['sys_num'])->update($data);
$ress = OrderList::where("id",$request['id'])->update($data);
if($res && $ress){
self::operating_time($orderListArr['serial_number'],'安装预约时间',date("Y-m-d H-i-s"),$orderListArr['order_num'],$session);//订单操作时间
self::updateLineSrate($request['coordinate'], 2, $orderListArr['serial_number'], $orderListArr['sys_num'], $orderListArr['order_num']);
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
// 检验
public static function inspect($request)
{
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 2) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单不是待检验,无法检验!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法检验!', 'Data' => []];
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
DB::beginTransaction();
$find_orli_data = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'stauas')
->get()->toArray();
if (empty($find_orli_data)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$find_orli_data = objectToArray($find_orli_data);
// 批量添加时间节点
foreach ($find_orli_data as $key => $val) {
timeLog($val['serial_number'], $find_design_order['order_num'], $user_info->install_name, "检验时间", date('Y-m-d H:i:s'));
}
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 3; //工单状态:1未接单2已接单3安装中
$service_data['service_state'] = 4; //技师服务状态:0未派单1未接单2已接单(未检验)3已拒单4已检验5安装中6完成待审核
$deor_res = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->update($service_data);
$order_res=DB::table('orders')
->where('id', $request['id'])
->update(['orders_sertatus'=>4]);
if ($deor_res && $order_res) {
DB::commit();
sertimeLog($find_design_order['sys_num'], $find_design_order['order_num'], $user_info->install_name, "检验时间", date('Y-m-d H:i:s'),$find_design_order['ser_id']);
return ['ErrorCode' => 1, 'ErrorMessage' => '检验成功', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '失败', 'Data' => []];
}
}
// 开始安装
public static function startInstall($request)
{
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 4) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单未检验!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法拒单!', 'Data' => []];
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
DB::beginTransaction();
$find_orli_data = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'stauas')
->get()->toArray();
if (empty($find_orli_data)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$find_orli_data = objectToArray($find_orli_data);
// 批量添加时间节点
foreach ($find_orli_data as $key => $val) {
timeLog($val['serial_number'], $find_design_order['order_num'], $user_info->install_name, "开始安装", date('Y-m-d H:i:s'));
}
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 3; //工单状态:1未接单2已接单3安装中
$service_data['service_state'] = 5; //技师服务状态:0未派单1未接单2已接单3已拒单4已检验5安装中6已安装完成
$deor_res = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->update($service_data);
$order_res=DB::table('orders')
->where('id', $request['id'])
->update(['orders_sertatus'=>5]);
if ($deor_res && $order_res) {
DB::commit();
// czrzLog("拒单,", $find_design_order['serial_number'], "移动端技师拒单", "订单系统", request::ip(), $user_info->install_name);
sertimeLog($find_design_order['sys_num'], $find_design_order['order_num'], $user_info->install_name, "开始安装", date('Y-m-d H:i:s'),$find_design_order['ser_id']);
return ['ErrorCode' => 1, 'ErrorMessage' => '已开始施工', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '开始施工失败', 'Data' => []];
}
}
// 申请完成
public static function installFeedback($request)
{
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 5) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单未安装!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单已锁定,无法拒单!', 'Data' => []];
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
// 获取所有的工单数据
$order_list = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'service_state','orli_reject')
->get();
if (empty($order_list)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$order_list = objectToArray($order_list);
// 顺便判断一下工单状态
foreach ($order_list as $key => $val) {
if ($val['service_state'] != 5 && $val['service_state'] != 6) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单不是施工反馈状态!', 'Data' => []];
}
}
DB::beginTransaction();
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 4; //工单状态:1未接单2已接单3安装中4待完成5已完成6已拒单7已撤销
$service_data['service_state'] = 6; //技师服务状态:0未派单1未接单2已接单3已拒单4已检验5安装中6已安装完成
$service_data['update_time'] = date('Y-m-d H:i:s');
$service_data['orli_reject'] = 1;
// 更改服务工单结算表
$seli_edit_data=[];
$seli_edit_data['list_service_type'] = $service_data['stauas']; //派工单状态:1未接单2已接单【废弃】3安装中4完成待审核5已完成6已拒单7已撤销8延期审图9延期结算
$seli_edit_data['update_time'] = date('Y-m-d H:i:s'); //更新时间
$is_edit=0;
$is_over=0;
$deor_res=true;
foreach ($order_list as $key => $val) {
if($val['service_state']==6 && $val['orli_reject']==1){
$is_edit++;
continue;
}
// 部分完成则判断是否有上传图片
if($request['type']==1){
// 判断是否有图片反馈
$feed_res=Db::table('feedback')
->where('gl_id',$val['id'])
->where('is_delete', 1)
->select("id")
->get()->toArray();
if(empty($feed_res)){
$is_over++;
continue;
}
}
$is_edit++;
// 更改工单信息
$orli_res = DB::table('order_list')
->where('id', $val['id'])
->update($service_data);
if(!$orli_res){
$deor_res=$orli_res;
}
$seli_edit_res = DB::table('settlement_list')
->where('serial_number', $val['serial_number'])
->where('list_id', $val['id'])
->update($seli_edit_data);
timeLog($val['serial_number'], $find_design_order['order_num'], $user_info->install_name, "反馈时间", date('Y-m-d H:i:s'));
}
$order_data=[];
$order_data['order_status'] = 8;
$order_data['update_time'] = date('Y-m-d H:i:s');
$order_data['orders_sertatus']=5;
if($is_over==0){
$order_data['orders_sertatus']=6;
}
// 更改订单信息
$ord_res = DB::table('orders')
->where('id', $find_design_order['id'])
->update($order_data);
if ($deor_res && $ord_res) {
DB::commit();
$str=$order_data['orders_sertatus']==5?'部分反馈':'反馈时间';
sertimeLog($find_design_order['sys_num'], $find_design_order['order_num'], $user_info->install_name, $str, date('Y-m-d H:i:s'),$find_design_order['ser_id']);
return ['ErrorCode' => 1, 'ErrorMessage' => '施工申请完成', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '申请完成失败', 'Data' => []];
}
}
// 施工图片反馈
public static function imageFeedback($request){
// 查询工单表信息
$find_design_order = DB::table('order_list')
->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'serial_number', 'sys_num', 'order_num', 'ord_id', 'service_state', 'lock_state', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['service_state'] != 5) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单状态错误!', 'Data' => []];
}
$find_inpe_data = DB::table('install_person')
->where('admin_id', $request['admin_id'])
->where('delet_y', 1)
->select('install_name', 'install_phone')
->first();
$find_inpe_data = objectToArray($find_inpe_data);
// 查询成员账号信息表
$find_adm_data = DB::table('admin')
->where('id', $request['admin_id'])
->select('admin_acc', 'company_name')
->first();
$find_adm_data = objectToArray($find_adm_data);
$image_url=$request['image_url'];
$image_id=$request['image_id'];
$image_type=$request['image_type'];
if($image_url =='undefined'){
return ['ErrorCode' => 500, 'ErrorMessage' => $image_type.'上传失败请重新上传', 'Data' => []];
}
DB::beginTransaction();
$edit_res=true;
// 不是0 则为编辑
if($image_id != 0){
$image_data=Db::table('feedback')
->where('gl_id',$request['id'])
->where('is_delete', 1)
->where('id',$image_id)
->select('feedback_pic')
->first();
if(!empty($image_data)){
$image_path=$image_data->feedback_pic;
// http://3m127.bluearp.com/storage/app/public/image/2022/11/15/166848425637152.jpg
// http://3m127.bluearp.com/storage/image/2022/11/15/166848420917354.jpg
// url 路径里 app/public 被忽略了;
// $image_path=str_replace('storage/image','storage/app/public/image',$image_path);
// $image_path=substr($image_path,strpos($image_path,'storage/app'));
$image_path=substr($image_path,strpos($image_path,'storage'));
// dd(11);
if(file_exists($image_path)){
unlink($image_path);
}
Db::table('feedback')
->where('gl_id',$request['id'])
->where('is_delete', 1)
->where('id',$image_id)
->delete();
}
}
$add_feed=[];
$add_feed['type'] = 1; //图片类型
$add_feed['gl_id'] = $request['id']; //反馈关联id
$add_feed['install_name'] = $find_inpe_data['install_name']; //安装人员姓名
$add_feed['install_phone'] = $find_inpe_data['install_phone']; //安装电话
$add_feed['install_remark'] = ''; //安装备注
$add_feed['install_time'] = date('Y-m-d H:i:s'); //安装时间
$add_feed['admin_id'] = $request['admin_id']; //所属服务中心id
$add_feed['company_name'] = $find_adm_data['company_name']; //服务中心名称
$add_feed['feedback_status'] = 2; //是否安装
$add_feed['feedback_pic'] = $image_url; //凭证图片
$add_feed['sys_num'] = 'rwfk' . $request['id']; //所属服务中心id
$add_feed['is_type'] = 2; //1微信2第三方
$add_feed['type_name'] = $image_type; //类型名称
$add_feed_id = DB::table('feedback')->insertGetId($add_feed);
if ($add_feed_id && $edit_res) {
DB::commit();
return ['ErrorCode' => 1, 'ErrorMessage' => '图片回传成功', 'Data' => ['feed_id'=>$add_feed_id]];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => $add_feed_id.'图片回传失败'.$edit_res, 'Data' => []];
}
}
// 施工时 车牌车架号反馈
public static function LicenseFeedback($request){
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 5) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单状态错误!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法反馈!', 'Data' => []];
}
$license_plate=$request['license_plate'];
if($license_plate != ''){
$repeat_res = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('is_delete', 1)
->where('id','<>',$request['gd_id'])
->where('license_plate',$license_plate)
->select('id')
->get()
->toArray();
if(!empty($repeat_res)){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '车牌/车架号填写重复', 'Data' => []];
}
}
$res=DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('is_delete', 1)
->where('id',$request['gd_id'])
->update(['license_plate'=>(string)$license_plate,'update_time'=>date('Y-m-d H:i:s')]);
if($res){
return ['ErrorCode' => 1, 'ErrorMessage' => '回传车架号成功', 'Data' => []];
}else{
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '保存车架号失败', 'Data' => []];
}
}
// 获取工单反馈信息
public static function getFeedback($request)
{
// 查询服务单表信息
$orders_data = DB::table('orders')
->where('id', $request['id'])
->where('is_delete', 1)
->select('id','sys_num')
->first();
if (empty($orders_data)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务单', 'Data' => []];
}
// 获取所有的工单数据
$order_list = DB::table('order_list')
->where('sys_num', $orders_data->sys_num)
->where('is_delete', 1)
->select('id','serial_number',"sys_num", 'license_plate','service_state','orli_reject')
->orderBy('service_state')
->get();
if (empty($order_list)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到工单', 'Data' => []];
}
$order_list = objectToArray($order_list);
$no_pic=[];
$no_pic['gl_id'] = 0;
$no_pic['feedback_pic'] = config('apisystem.HTTP_URL') . 'image/icon/webapp_no_pictures.png';
$no_pic['type_name'] = '暂无图片';
foreach ($order_list as $key => $val) {
// 查询反馈信息
$list_data = DB::table('feedback')
->where('gl_id',$val['id'])
->where('is_delete', 1)
->select("id",'gl_id', 'feedback_pic', 'type_name')
->orderBy('type_name','asc')
->get()->toArray();
if (empty($list_data)) {
$list_data = [$no_pic];
}
$order_list[$key]['list_data']=$list_data;
}
return ['ErrorCode' => 1, 'ErrorMessage' => '获取信息成功', 'Data' => $order_list];
}
// 获取技师
public static function getInstallPerson($request)
{
// 查询工单表信息
$find_inpe_data = InstallPerson::where('delet_y', 1)
->where('admin_id', $request['admin_id'])
->where('install_is_type', 1) //状态:1启用2停用
->where(function ($query) use ($request) {
if (!empty($request['install_name'])) {
$query->where('check_code', 'like', '%' . $request['install_name'] . '%')
->orWhere('install_name', 'like', '%' . $request['install_name'] . '%');
}
})
->select('id', 'check_code', 'install_name')
->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_inpe_data];
}
// 获取标签
public static function getLabel($request)
{
// 查询工单表信息
$find_sety_data = DB::table('setmoney_type')
->where('lt_parent_id', 694)
->where('lt_statues', 1)
->where(function ($query) use ($request) {
if (!empty($request['sety_name'])) {
$query->where('sety_name', 'like', '%' . $request['sety_name'] . '%');
}
})
->select('sety_id', 'sety_name')
->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_sety_data];
}
// 获取操作记录
public static function operatingRecord($request)
{
// 查询操作表信息
$find_data = DB::table('orderserver_time')
->where('serial_number', $request['serial_number'])
->where('ser_id', $request['admin_id'])
->select('create_time', 'is_type')
->orderby('id', 'desc')
->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_data];
}
/**|---------------------------------------------------------------------------------
* @name 工单状态
* @param string $type
* @retrun /multitype:array
* @author dou 2024/9/10 10:51
* |---------------------------------------------------------------------------------
*/
public static function getStauasName ( $type = true ){
$stauasName = [['type'=>'1','name'=>'未处理'],['type'=>'10','name'=>'处理中'],['type'=>'15','name'=>'客服介入'],['type'=>'30','name'=>'审核中'],['type'=>'40','name'=>'已完成']];
if($type){
$stauasName = CommonService::jointArrayKey($stauasName, 'type');
}
return $stauasName;
}
// 订单操作时间
public static function operating_time($num,$type,$time,$order_num,$session){
$data['serial_number']=$num;
$data['create_name']=$session['install_name'];
$data['is_type']=$type;
$data['create_time']=$time;
$data['order_num']=$order_num;
$result = OrderTime::insert($data);
if($result){
return 1;
}else{
return 2;
}
}
//添加时间戳
public static function add_thistory ($number,$timetype,$time,$ser_id,$type,$session){
if($type==1){
$poss[$timetype]=strtotime($time);
$poss['tih_serid']=$ser_id;
$poss['tih_number']=$number;
$poss['company_type']=$session['install_name'];
DB::table('time_history')->insert($poss);
}else{
$poss[$timetype]=strtotime($time);
DB::table('time_history')->where("tih_number",$number)->update($poss);
}
}
/**|---------------------------------------------------------------------------------
* @name 同步施工节点
* @param string $coordinate 坐标
* @param string $line_state 节点状态
* @param string $line_serm 工单号
* @param string $line_sysnum 系统单号
* @param string $line_number 单号
* @retrun \Illuminate\Http\JsonResponse /multitype:array
* @author dou 2024/9/11 0:45
* |---------------------------------------------------------------------------------
*/
public static function updateLineSrate ( $coordinate , $line_state , $line_serm , $line_sysnum , $line_number ){
$install_line = InstallLine::where("line_serm",$line_serm)->first();
switch ( $line_state ){
case 2:
$line['line_contact'] = $coordinate;
$line['line_contact_time'] = date("Y-m-d H:i:s");
break;
case 3:
$line['line_start'] = $coordinate;
$line['line_start_time'] = date("Y-m-d H:i:s");
break;
case 4:
$line['line_arrive'] = $coordinate;
$line['line_arrive_time'] = date("Y-m-d H:i:s");
break;
case 5:
$line['line_task'] = $coordinate;
$line['line_task_time'] = date("Y-m-d H:i:s");
break;
case 6:
$line['line_end'] = $coordinate;
$line['line_end_time'] = date("Y-m-d H:i:s");
break;
default:
return false;
break;
}
$line['line_lasttime'] = date("Y-m-d H:i:s");
$line['line_state'] = $line_state;
if(empty($install_line)){
$line['line_serm'] = $line_serm;
$line['line_sysnum'] = $line_sysnum;
$line['line_number'] = $line_number;
$line['line_serm'] = $line_serm;
$res = InstallLine::insert($line);
}else{
$line_states = $line_state-1;
if($line_states < $install_line['line_state']){
return false;
}else{
$res = InstallLine::where("line_serm",$line_serm)->update($line);
}
}
return $res;
}
#计算奖惩金额以及评分
public static function calculates($dou,$orderListArr,$supply_price,$manhourfee,$session){
#商品供货金额
$money['sem_slid'] = $dou;
$money['sem_synum'] = $orderListArr['sys_num'];
$money['sem_price'] = $manhourfee;
$money['sem_creacter'] = $session['install_name'];
$money['sem_type'] = 1;
$money['add_time'] = date("Y-m-d H:i:s");
SettlementMoney::insert($money);
// #开始计算奖惩金额以及评分
// $payout_time = OrderTime::where('serial_number',$orderListArr['serial_number'])
// ->where('is_type','起始时间')
// ->orderBy('id','DESC')
// ->value('create_time');//获取奖罚起始时间
// $zero1 = time();
// $zero2 = strtotime($payout_time);
// $guonian = ($zero1-$zero2)/60;
// #计算评分
// if($guonian<=5){
// $score['orsc_grade'] = 5;
// }if($guonian>5 && $guonian<=10){
// $score['orsc_grade'] = 2;
// }if($guonian>10){
// $score['orsc_grade'] = 1;
// }
// $score['orsc_sernum'] = $orderListArr['serial_number'];
// $score['orsc_slid'] = $dou;
// $score['orsc_creacter'] = $session['install_name'];
// $score['orsc_type'] = 1;
// DB::table("order_score")->insert($score);
// //默认生成平台评分十分
// $scoreq['orsc_grade'] = 5;
// $scoreq['orsc_sernum'] = $orderListArr['serial_number'];
// $scoreq['orsc_slid'] = $dou;
// $scoreq['orsc_creacter'] = $session['install_name'];
// $scoreq['orsc_type']=2;
// DB::table("order_score")->insert($score);
}
}
<?php
namespace App\Services\Api\MobileWeb;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;
use BlueCity\Core\Inc\ErrorInc;
use App\Models\{Admin,
GhPrice,
GoodsBrand,
InstallLine,
Management,
Note,
OrderList,
OrderMsg,
OrderRejected,
Orders,
InstallPerson,
OrderTime,
SetmoneyType,
SettlementList,
SettlementMoney,
SubmitPlease,
User,
OrderAfter
};
use App\Services\{BmmcService, Api\OrderManage\OrdersVehicleService, CommonService};
class StatementsListService extends Model
{
/**
* 售后列表
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $request [description]
* @param integer $show_count [description]
* @return [type] [description]
*/
public static function index($request, $show_count = 10)
{
$session = $request['session'];
// 查询列表
if ($request['status'] == 1) {//未出账单
$list_data = DB::table('settlement_list as s')
->leftJoin('order_list as o', 'o.serial_number', '=', 's.list_id')
->leftJoin('order_msg as om', 'om.id', '=', 'o.order_goods_id')
->where('s.ser_id', $session['admin_id'])
->where('list_service_type', 40)
->whereIn('sett_status', [1,60,63])
->select('s.id','s.sys_num', 's.create_time', 'all_price', 'list_id', 'om.goods_name', 'om.goods_num')
->paginate($show_count);
$page['count'] = 0;
$page['page'] = 0;
$page['page_size'] = $show_count;
$page['allPage'] = 0;
$data['list'] = [];
$data['page'] = $page;
$list_items = $list_data->items();
if ($list_items) {
$list_items = CommonService::dataToArray($list_items);
$page['count'] = $list_data->total(); //总数据个数
$page['page'] = $list_data->currentPage(); //当前页面页码
$page['page_size'] = $show_count; //一页显示多少个
$page['allPage'] = $list_data->lastPage(); //表示最后一页的页码
$data['list'] = $list_items;
$data['page'] = $page;
}
} else {//已出账单
$list_data = DB::table('statements_list as sl')
->leftJoin('company as c', 'c.com_id', '=', 'sl.company_id')
->where('stl_serid', $session['admin_id'])
// ->where('stl_type', '!=', 4)
->select('stl_wat', 'stl_type', 'com_name', 'stl_startime', 'stl_endtime', 'stl_money')
->orderByRaw("stl_type asc,stl_endtime desc")
->paginate($show_count);
$page['count'] = 0;
$page['page'] = 0;
$page['page_size'] = $show_count;
$page['allPage'] = 0;
$data['list'] = [];
$data['page'] = $page;
$list_items = $list_data->items();
if ($list_items) {
$list_items = CommonService::dataToArray($list_items);
$getStauasName = self::getStauasName();
foreach ($list_items as $key => $value) {
$list_items[$key]['stl_type_name'] = $getStauasName[$value['stl_type']]['name'];
$list_items[$key]['button'] = [];
$list_items[$key]['button'] = [['action'=>'info','name'=>'查看详情']];
if(in_array($value['stl_type'],[1])){
$list_items[$key]['button'][] = ['action'=>'businessFirm','name'=>'商家确认'];
}
}
$page['count'] = $list_data->total(); //总数据个数
$page['page'] = $list_data->currentPage(); //当前页面页码
$page['page_size'] = $show_count; //一页显示多少个
$page['allPage'] = $list_data->lastPage(); //表示最后一页的页码
$data['list'] = $list_items;
$data['page'] = $page;
}
}
if ($data['list']) {
return ['ErrorCode' => 1, 'ErrorMessage' => '成功', 'Data' => $data];
} else {
return ['ErrorCode' => 1, 'ErrorMessage' => '暂无数据', 'Data' => $data];
}
}
/**|---------------------------------------------------------------------------------
* @name 工单状态
* @param string $type
* @retrun /multitype:array
* @author dou 2024/9/10 10:51
* |---------------------------------------------------------------------------------
*/
public static function getStauasName ( $type = true ){
$stauasName = [['type'=>'1','name'=>'未确认'],['type'=>'2','name'=>'已确认'],['type'=>'3','name'=>'已结算'],['type'=>'30','name'=>'审核中'],['type'=>'4','name'=>'已完成']];
if($type){
$stauasName = CommonService::jointArrayKey($stauasName, 'type');
}
return $stauasName;
}
/**|---------------------------------------------------------------------------------
* @name 立即处理
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* |---------------------------------------------------------------------------------
*/
public static function handle_ive ($request)
{
DB::beginTransaction();
$session = $request['session'];
$find_data = DB::table('order_after')
->where('id', $request['id'])
->first();
$order_num = $find_data['order_num'];
$status = $find_data['status'];
if ($status !=1){
return ['ErrorCode' => 2, 'ErrorMessage' => '售后状态不正确', 'Data' => ''];
}
$feek_time = date('Y-m-d',strtotime("+1day")).' 17:30:00'; //明天下午5:30时间
$info['feek_time'] = $feek_time;
$info['status'] = 10; //改为处理中
$info['day_time'] = $request['appoint_time'];
$res = OrderAfter::where('id',$request['id'])->update($info);
if ($res){
$rest = CommonService::accMe($find_data['sys_num'],'售后列表',$request['quality_content'],$find_data['sys_num'],2,2,$session['install_name'],$session['install_id']);
if ($rest){
CommonService::inserting_log('售后列表',$find_data['sys_num'],'售后处理','售后列表',$session,$request['ip']);//日志
//修改领取人
$get_id = OrderAfter::where('id',$request['id'])->value('get_id');
if(!$get_id){
OrderAfter::where('id',$request['id'])->update(['get_id'=>$session['id'],'get_time'=>date("Y-m-d H:i:s")]);
}
DB::commit();
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
/**
* 日常反馈
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $data [description]
* @return [type] [description]
*/
public static function dailyFeedback($request) {
$session = $request['session'];
$find_data = DB::table('order_after')
->where('id', $request['id'])
->first();
DB::beginTransaction();
$rest = CommonService::accMe($find_data['sys_num'],'售后列表',$request['remark'],$find_data['sys_num'],2,2,$session['install_name'],$session['install_id']);
if ($rest){
CommonService::inserting_log('售后列表',$find_data['sys_num'],'日常反馈','售后列表',$session,$request['ip']);//日志
DB::commit();
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
/**
* 详情
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $data [description]
* @return [type] [description]
*/
public static function info($data) {
$session = $data['session'];
$find_data = DB::table('order_after')
->where('id', $data['id'])
->select('id', 'after_num', 'shr_id', 'shr_name', 'shr_phone', 'shr_address', 'shr_sheng', 'shr_shi','shr_xian', 'good_names', 'create_time', 'deal_sertime', 'finish_time', 'status', 'sys_num', 'day_time', 'serial_number')
->first();
$remark = CommonService::orderRemarks($find_data['sys_num'],'',2,$session['install_id']);
$image = DB::table('feedsales')
->where('gl_id', $find_data['id'])
->where('sys_num', $find_data['sys_num'])
->get();
if(in_array($find_data['status'],[1])){
$find_data['button'] = [['action'=>'handle_ive','name'=>'立即处理']];
}
if(in_array($find_data['status'],[10])){
$find_data['button'] = [['action'=>'quality','name'=>'申请完成'],['action'=>'dailyFeedback','name'=>'日常反馈']];
}
$return_data['data'] = $find_data;
$return_data['remark'] = $remark ? $remark : [];
$return_data['image'] = $image;
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => $return_data];
}
/**
* 申请完成
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-12
* @param [type] $data [description]
* @return [type] [description]
*/
public static function quality($data) {
$session = $data('session');
$find_data = OrderAfter::where('id',$data['id'])->first();
$serial_number = $find_data['serial_number'];
if($find_data['status']==1 || $find_data['status']==10 || $find_data['status']==15){
}else{
return ['ErrorCode' => 2, 'ErrorMessage' => '售后状态错误', 'Data' => []];
}
Db::beginTransaction();
$rest = CommonService::accMe($find_data['sys_num'],"售后订单","【售后】申请完成,".$data['quality_content'],$serial_number,'2',$session['admin_groupnew'],$session['admin_acc'],$session['id']);
if($rest){
if ($data['file'] && $data['file'] != []){
$company_name = Admin::where('id',$find_data['deal_serid'])->value("company_name");
$inst = InstallPerson::where('admin_id',$find_data['deal_serid'])->first();//安装人员
$sql = 'INSERT INTO gone_feedsales (`type`,`gl_id`,`install_name`,`install_phone`,`install_time`,`admin_id`,`company_name`,`feedback_status`,`sys_num`,`is_type`,`feedback_pic`) VALUES';
$num = 0;
foreach($data['file'] as $key=>$val){
$num = $num + 1;
$sql .= "('".$num."','".$data['id']."','".$inst['install_name']."','".$inst['install_phone']."','".date("Y-m-d H:i:s")."','".$find_data['deal_serid']."','".$company_name."','2','".$find_data['after_num']."','2','".$val."'),";
}
$sql = substr($sql,0,strlen($sql) - 1);
DB::insert($sql);
}
$get['deal_time'] = date("Y-m-d H:i:s");
$get['status'] = '30';
$get['trigyn'] = '1';
if($Olaf['get_id'] < 1){
$get['get_id'] = $session['id'];
$get['get_time'] = date("Y-m-d H:i:s");
}
$result = OrderAfter::where('id',$Input['id'])->update($get);
if($result){
$after_num = OrderAfter::where('id',$Input['id'])->select('after_num','p_id')->first();
$get['after_num'] = $after_num['after_num'];
DB::commit();
$this->operatingTime($Input['sys_num'],'申请质保完成时间',date("Y-m-d H:i:s"),$Olaf['order_num'],$session['admin_acc']);//订单操作时间
$this->insertingLog("申请质保完成,",$Input['sys_num'],"订单(".$serial_number.")","派工单列表",$request->ip(),$session['admin_acc']);//日志
return $this->success('操作成功');exit;
}else{
DB::rollBack();
return $this->error('操作失败', ErrorInc::MYSQL_FAILED);exit; }
}else{
DB::rollBack();
return $this->error('添加备注失败', ErrorInc::MYSQL_FAILED);exit;
}
}
/**|---------------------------------------------------------------------------------
* @name 获取接单技师
* @param int $request 请求参数
* @param int $old_install_id 老技师id
* @retrun \Illuminate\Http\JsonResponse
* @author dou 2024/9/10 16:36
* |---------------------------------------------------------------------------------
*/
public static function getPerson ( $request , $old_install_id = 0 ){
$session = $request['session'];
$order_list = OrderList::where('id',$request['id'])->select('ser_id','customer_id')->first();
if($order_list){
$dress = User::where('id',$order_list['customer_id'])->select('shr_sheng','shr_shi','shr_xian','shr_adress')->first();
$end = CommonService::jingwei($dress['shr_sheng'], $dress['shr_sheng'].$dress['shr_shi'].$dress['shr_xian'].$dress['shr_adress']);
if(empty($old_install_id)) {
$list = InstallPerson::where('install_is_type',1)
->where('delet_y',1)
->where('admin_id',$session['admin_id'])
->select('id','install_name','longitude','latitude','install_province','install_city','install_cuntry','install_address')
->get();
}else{
$list = InstallPerson::where('install_is_type',1)
->where('delet_y',1)
->where('admin_id',$session['admin_id'])
->where('id','!=',$old_install_id)
->select('id','install_name','longitude','latitude','install_province','install_city','install_cuntry','install_address')
->get();
}
if($list){
$list = CommonService::dataToArray($list);
foreach( $list as $kri => $vri ){
if($vri['longitude'] && $vri['latitude']){
$start = $vri['longitude'].','.$vri['latitude'];
}else{
$start = CommonService::jingwei($vri['install_province'],$vri['install_province'].$vri['install_city'].$vri['install_cuntry'].$vri['install_address']);
}
if($vri['install_address']=='' || $start ==''){
$list[$kri]['juli'] = '';
$list[$kri]['jl'] = 100000;
$lists[] = $list[$kri];
unset($list[$kri]);continue;
}else{
$jingwei[] = $start;
}
}
if(!empty($jingwei) && !empty($end)){
$jingwei = implode('|', $jingwei);
$res = CommonService::juli($jingwei,$end,2);
}else{
$res = [];
}
$num_ = 0;
foreach ($list as $k => $v) {
if (!isset($res[$num_])) {
$list[$k]['juli'] = '';
$list[$k]['jl'] = 100000;
} else {
$list[$k]['juli'] = round($res[$num_]['distance']/1000,2) . '公里';
$list[$k]['jl'] = round($res[$num_]['distance']/1000,2);
}
$num_++;
}
if(!empty($lists) && !empty($list)) {
$list = array_merge($list, $lists);
}elseif (!empty($lists)){
$list = $lists;
}
$list = CommonService::resetListKey($list);
foreach($list as $k => $v){
$num[]=$v['jl'];
if($v['jl'] == 100000){
unset($list[$k]['jl']);
}
}
array_multisort($num, SORT_NUMERIC ,SORT_ASC, $list);
return ['ErrorCode' => 1, 'ErrorMessage' => '暂无数据', 'Data' => $list];
}else{
return ['ErrorCode' => 1, 'ErrorMessage' => '无可派单技师', 'Data' => $list];
}
}else{
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未获取订单信息', 'Data' => ''];
}
}
// 接单
public static function receiving($request,$ip)
{
$session = $request['session'];
// 查询服务单表信息
$orderListArr = OrderList::where('id',$request['id'])
->where('is_delete', 1)
->first();
if(empty($orderListArr)){
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$orderListArr = CommonService::dataToArray($orderListArr);
// 判断是否派单是否锁定
if(!in_array($orderListArr['stauas'], [10,20])){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单不是待接单状态!', 'Data' => []];
}
if ($orderListArr['locklist_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法接单!', 'Data' => []];
}
$MsgArr = OrderMsg::where('id',$orderListArr['order_goods_id'])
->select("goods_id","goods_name","goods_brand","goods_price")
->first();
$goods_name = $MsgArr['goods_name'];
$goods_id = $MsgArr['goods_id'];
$goods_brands = $MsgArr['goods_brand'];
$goods_name=trim($goods_name,',');
$goods_id=trim($goods_id,',');
$instArr = InstallPerson::where('id',$request['receive_install_id'])
->select("install_name","install_phone","plate_num")
->first();
if(!$instArr){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '技师不存在!', 'Data' => []];
}
$supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
->where('ser_id',$orderListArr['ser_id'])
->orderBy('id','Desc')
->value('supply_price');
if(!$supply_price){
$supply_price = GhPrice::where('goods_id',$MsgArr['goods_id'])
->where('ser_id',0)
->orderBy('id','Desc')
->value('supply_price');
if(!$supply_price){
$supply_price='0.00';
}
}
//end Dong
$arr['sys_num']=$orderListArr['sys_num']; //系统单号
$arr['order_num']=$orderListArr['order_num']; //平台单号
$arr['serial_number']=$request['id']; //关联的order_list_id
$arr['msg_id']=$orderListArr['order_goods_id']; //关联msg_id
$arr['p_id']=$orderListArr['p_id']; //平台id
$arr['list_id']=$orderListArr['serial_number']; //派工单编号
$arr['ser_id']=$orderListArr['ser_id']; //服务中心id
$arr['type']=2; //出售方式
// 上门安装
$arr['installperson']=$request['receive_install_id']; // 安装人id
$arr['intall_person']=$instArr['install_name'];// 安装人名称
$arr['intall_phone']=$instArr['install_phone'];// 安装人电话
$is_bool="到店安装";
$info['installation']=2;//安装分类(上门安装)
// 供货价
$arr['order_price']=$supply_price; //供货价
// 总金额
$all_price=$supply_price; //Dong
$arr['all_price']=$all_price;
// 结算状态
$arr['sett_status']=1;
// 工单状态
$arr['list_service_type']=30;
// 客户id
$arr['customer_id']=$orderListArr['customer_id'];
$arr['category']=$orderListArr['category'];
$arr['sel_type']=$orderListArr['orli_type'];
$arr['pay_types']=$orderListArr['pay_typel'];//支付方式
$arr['goods_brand']=$goods_brands;
// 锁定状态
$submit_stauas = SubmitPlease::where('submit_sys_num',$orderListArr['sys_num'])->where('msg_id',$orderListArr['order_goods_id'])->orderBy('id','DESC')->value('submit_stauas');
if($submit_stauas==1){
$arr['locked']=2;
}
/**追 溯**/
$times=date('Y-m-d H:i:s');
$sometime=substr(date('Y-m-d H:i:s',strtotime("$times-2 month")),0,10);//入仓时间
$info['goods_name']=$goods_name;//产品名称
$info['manufacturer']=GoodsBrand::where("brand_name",$MsgArr['goods_brand'])
->where('company_id',$orderListArr['company_id'])
->value('brand_remark');//生产厂家
$info['transport']=$sometime;//入仓时间
$info['order_time']=substr($times,0,10);//下单时间
$info['install_one']=$instArr['install_name'];//安装人
$info['replacing_time']=substr(date('Y-m-d H:i:s',strtotime('+2 year')),0,10);//建议更换时间
/**派工单**/
$post['stauas']=30;//派工单状态
$post['install_id']=$_POST['id'];//安装人id
$post['intall_person']=$instArr['install_name'];//安装人姓名
$post['intall_phone']=$instArr['install_phone'];//安装人电话
$post['goods_brand']=$goods_brands;
$post['goods_type']=3; //接单直接到安装中,略过检验 Dong
$post['get_time']=date("Y-m-d H:i:s");
/**订 单**/
$get['order_status']=30;//订单状态
$get['intall_person']=$instArr['install_name'];//安装人姓名
$get['intall_phone']=$instArr['install_phone'];//安装人电话
$returncount = OrderList::where('sys_num',$orderListArr['sys_num'])
->where('stauas',20)
->count();
DB::beginTransaction(); //开启事务
if($returncount==1){
$restOrderList = OrderList::where('id',$request['id'])->update($post);
$restOrder = Orders::where('sys_num',$orderListArr['sys_num'])->update($get);
if($restOrderList && $restOrder){
$restult=1;
}else{
$restult=0;
}
}else{
$restOrderList = OrderList::where('id',$request['id'])->update($post);
if($restOrderList){
$restult=1;
}else{
$restult=0;
}
}
$arr['company_id']=$orderListArr['company_id'];
$arr['agency_id']=$orderListArr['agency_id'];
$dou=SettlementList::insertGetId($arr);
if($restult==1 && $dou){
DB::commit();
Management::where('trace_code',$orderListArr['serial_number'])->update($info);
if($dou){
self::calculates($dou,$orderListArr,$supply_price,$supply_price,$session);//计算奖惩金额以及评分
}
$weixin['ser_id'] = $_POST['id'];
$weixin['order_num'] = $orderListArr['order_num']; //平台单号
$weixin['goods_name'] = '安装服务';//$v['goods_name'];
$weixin['serial_number'] = $orderListArr['serial_number'];
$weixin['install_type'] = 2;
CommonService::requestPost('http://zptzchat.bluearp.com/m/index.php/BindingAccount/push_order', $weixin);
//begin Dong
$company_name = Admin::where('id',$orderListArr['ser_id'])->select("admin_acc","company_name","reward")->first();//服务中心名称
$douId = SettlementList::where('list_id',$orderListArr['serial_number'])->value('id');
$res = SettlementMoney::where('sem_slid',$douId)->where('sem_type',17)->first();
if(!$res){
$payout_time = OrderTime::where("serial_number",$orderListArr['serial_number'])->where("is_type",'接单时间')->orderBy("id",'DESC')->value('create_time');//获取奖罚起始时间
$money_type = SetmoneyType::where("sety_id",'17')->pluck('sety_price','sety_id');
$zero1=time();//strtotime (date("Y-m-d H:i:s")); //当前时间 ,注意H 是24小时 h是12小时
$zero2=strtotime ($payout_time); //过年时间,不能写2014-1-21 24:00:00 这样不对
$guonian=($zero1-$zero2)/60; //60s*60min*24h
if($guonian<=17 && $company_name['reward']){
$money['sem_slid']=$douId;
$money['sem_synum']=$orderListArr['sys_num'];
$money['sem_creacter']=$company_name['admin_acc'];
$money['sem_price']=$money_type[17];
$money['sem_type']=17;
SettlementMoney::insert($money);
$all_price['all_price'] = SettlementMoney::where('sem_slid',$douId)->sum('sem_price');
SettlementList::where("id",$douId)->update($all_price);
}
}
//end Dong
$content = "订单".$is_bool."(".$orderListArr['serial_number'].")";
self::operating_time($orderListArr['serial_number'],'接单时间',date("Y-m-d H-i-s"),$orderListArr['order_num'],$session);//订单操作时间
self::add_thistory($orderListArr['serial_number'],'tih_acceptime',date("Y-m-d H:i:s"),$orderListArr['ser_id'],2,$session);//添加历史时间
CommonService::inserting_log('接单1,',$orderListArr['sys_num'],$content,'派工单',$session,$ip);//日志
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
// 拒单
public static function refuse($request,$ip)
{
$session = $request['session'];
$orderListArr = OrderList::where('id',$request['id'])->select("order_num","sys_num","stauas","ser_id","p_id","ol_dispamount","serial_number")->first();
$returncount = OrderList::where('sys_num',$orderListArr['sys_num'])->select("serial_number")->get();
$returncount = CommonService::dataToArray($returncount);
$serial_number = array_unique(array_column($returncount, 'serial_number')); //派工单号
if($orderListArr['stauas']<>10 && $orderListArr['stauas']<>20 && $orderListArr['stauas']<>30){
// 拒单失败!该单状态不正确!
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '订单状态错误请刷新后操作:检索码01', 'Data' => []];
}else{
if($orderListArr['stauas']!=$_POST['stauas']){
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '订单状态错误请刷新后操作:检索码02', 'Data' => []];
}
}
if(count($returncount) > 1 && $request['refuseType'] == 1){
// 该订单有多款商品,该工单不可拒单
return ['ErrorCode' => 201, 'ErrorMessage' => '订单包含多个商品是否全部拒单', 'Data' => []];
}
DB::beginTransaction(); //开启事务
$rest = CommonService::accMe($orderListArr['sys_num'], '派工单列表web', "拒单,".$_POST['note_content'], implode(',', $serial_number), 2, 2, $session['install_name'], $session['install_id']);
$resultOrderList = OrderList::where("sys_num",$orderListArr['sys_num'])->delete();
if($orderListArr['stauas']==30){
$settListArr = SettlementList::where("sys_num",$orderListArr['sys_num'])->where("sett_status",'>',1)->first();
if(!empty($settListArr)){
// 该单已审核
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '存在结算工单不可拒单', 'Data' => []];
}
$resultsettList = SettlementList::where("sys_num",$orderListArr['sys_num'])->delete();
}else{
$resultsettList = true;
}
$data['ser_id']=0;
$data['order_status']=10;
$resultOrder = Orders::where("sys_num",$orderListArr['sys_num'])->update($data);
if($resultOrderList && $rest && $resultsettList && $resultOrder){
DB::commit();
OrderTime::whereIn('serial_number',$serial_number)->delete();//删除工单操作时间
SettlementMoney::where('sem_synum',$orderListArr['sys_num'])->delete();//金额信息接单后生成
// M("settlement_count")->where("`cou_synum`='".$_POST['sys_num']."'")->delete();//评分信息接单后生成
DB::table('order_score')->whereIn("orsc_sernum",$serial_number)->delete();//评分信息接单后生成
Management::whereIn('trace_code',$serial_number)->delete();
CommonService::inserting_log('拒单,',$orderListArr['sys_num'],'订单('.$orderListArr['order_num'].')','派工单web',$session,$ip);//日志
self::operating_time($orderListArr['serial_number'],'拒单时间',date("Y-m-d H:i:s"),$orderListArr['order_num'],$session);//订单操作时间
OrderRejected::insert(['or_order_num'=>$orderListArr['order_num'],'or_ser_id'=>$orderListArr['ser_id'],'or_creact_time'=>date("Y-m-d H:i:s"),'or_centent'=>'门店自主拒单']);
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
DB::rollback();//回滚
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
/**|---------------------------------------------------------------------------------
* @name 预约安装
* @param int id 订单单号
* @param string day_time 预约是啊金
* @retrun \Illuminate\Http\JsonResponse /multitype:array
* @author dou 2024/9/11 0:36
* |---------------------------------------------------------------------------------
*/
public static function contact ( $request , $ip){
$session = $request['session'];
$orderListArr = OrderTime::where("id",$request['id'])->select("order_num","sys_num","stauas","ser_id","p_id","customer_id","serial_number","ol_dispamount")->first();
if($orderListArr['stauas'] <> 30){
// 拒单失败!该单状态不正确!
return ['ErrorCode' => ErrorInc::MYSQL_STEP_FAILED, 'ErrorMessage' => '订单状态错误请刷新后操作:检索码01', 'Data' => []];
}
$data['day_time']=$request['delay_time'];
$res = Orders::where("sys_num",$orderListArr['sys_num'])->update($data);
$ress = OrderList::where("id",$request['id'])->update($data);
if($res && $ress){
self::operating_time($orderListArr['serial_number'],'安装预约时间',date("Y-m-d H-i-s"),$orderListArr['order_num'],$session);//订单操作时间
self::updateLineSrate($request['coordinate'], 2, $orderListArr['serial_number'], $orderListArr['sys_num'], $orderListArr['order_num']);
return ['ErrorCode' => 1, 'ErrorMessage' => '操作成功', 'Data' => []];
}else{
return ['ErrorCode' => ErrorInc::MYSQL_FAILED, 'ErrorMessage' => '操作失败', 'Data' => []];
}
}
// 检验
public static function inspect($request)
{
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 2) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单不是待检验,无法检验!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法检验!', 'Data' => []];
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
DB::beginTransaction();
$find_orli_data = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'stauas')
->get()->toArray();
if (empty($find_orli_data)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$find_orli_data = objectToArray($find_orli_data);
// 批量添加时间节点
foreach ($find_orli_data as $key => $val) {
timeLog($val['serial_number'], $find_design_order['order_num'], $user_info->install_name, "检验时间", date('Y-m-d H:i:s'));
}
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 3; //工单状态:1未接单2已接单3安装中
$service_data['service_state'] = 4; //技师服务状态:0未派单1未接单2已接单(未检验)3已拒单4已检验5安装中6完成待审核
$deor_res = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->update($service_data);
$order_res=DB::table('orders')
->where('id', $request['id'])
->update(['orders_sertatus'=>4]);
if ($deor_res && $order_res) {
DB::commit();
sertimeLog($find_design_order['sys_num'], $find_design_order['order_num'], $user_info->install_name, "检验时间", date('Y-m-d H:i:s'),$find_design_order['ser_id']);
return ['ErrorCode' => 1, 'ErrorMessage' => '检验成功', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '失败', 'Data' => []];
}
}
// 开始安装
public static function startInstall($request)
{
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 4) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单未检验!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法拒单!', 'Data' => []];
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
DB::beginTransaction();
$find_orli_data = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'stauas')
->get()->toArray();
if (empty($find_orli_data)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$find_orli_data = objectToArray($find_orli_data);
// 批量添加时间节点
foreach ($find_orli_data as $key => $val) {
timeLog($val['serial_number'], $find_design_order['order_num'], $user_info->install_name, "开始安装", date('Y-m-d H:i:s'));
}
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 3; //工单状态:1未接单2已接单3安装中
$service_data['service_state'] = 5; //技师服务状态:0未派单1未接单2已接单3已拒单4已检验5安装中6已安装完成
$deor_res = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('order_num', $find_design_order['order_num'])
->where('is_delete', 1)
->update($service_data);
$order_res=DB::table('orders')
->where('id', $request['id'])
->update(['orders_sertatus'=>5]);
if ($deor_res && $order_res) {
DB::commit();
// czrzLog("拒单,", $find_design_order['serial_number'], "移动端技师拒单", "订单系统", request::ip(), $user_info->install_name);
sertimeLog($find_design_order['sys_num'], $find_design_order['order_num'], $user_info->install_name, "开始安装", date('Y-m-d H:i:s'),$find_design_order['ser_id']);
return ['ErrorCode' => 1, 'ErrorMessage' => '已开始施工', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '开始施工失败', 'Data' => []];
}
}
// 申请完成
public static function installFeedback($request)
{
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 5) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单未安装!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单已锁定,无法拒单!', 'Data' => []];
}
$user_info = CommonService::webgetUserInfo($request['api_token']);
// 获取所有的工单数据
$order_list = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('is_delete', 1)
->select('id', 'serial_number', 'service_state','orli_reject')
->get();
if (empty($order_list)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务工单', 'Data' => []];
}
$order_list = objectToArray($order_list);
// 顺便判断一下工单状态
foreach ($order_list as $key => $val) {
if ($val['service_state'] != 5 && $val['service_state'] != 6) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单不是施工反馈状态!', 'Data' => []];
}
}
DB::beginTransaction();
// 更改工单信息
$service_data=[];
$service_data['stauas'] = 4; //工单状态:1未接单2已接单3安装中4待完成5已完成6已拒单7已撤销
$service_data['service_state'] = 6; //技师服务状态:0未派单1未接单2已接单3已拒单4已检验5安装中6已安装完成
$service_data['update_time'] = date('Y-m-d H:i:s');
$service_data['orli_reject'] = 1;
// 更改服务工单结算表
$seli_edit_data=[];
$seli_edit_data['list_service_type'] = $service_data['stauas']; //派工单状态:1未接单2已接单【废弃】3安装中4完成待审核5已完成6已拒单7已撤销8延期审图9延期结算
$seli_edit_data['update_time'] = date('Y-m-d H:i:s'); //更新时间
$is_edit=0;
$is_over=0;
$deor_res=true;
foreach ($order_list as $key => $val) {
if($val['service_state']==6 && $val['orli_reject']==1){
$is_edit++;
continue;
}
// 部分完成则判断是否有上传图片
if($request['type']==1){
// 判断是否有图片反馈
$feed_res=Db::table('feedback')
->where('gl_id',$val['id'])
->where('is_delete', 1)
->select("id")
->get()->toArray();
if(empty($feed_res)){
$is_over++;
continue;
}
}
$is_edit++;
// 更改工单信息
$orli_res = DB::table('order_list')
->where('id', $val['id'])
->update($service_data);
if(!$orli_res){
$deor_res=$orli_res;
}
$seli_edit_res = DB::table('settlement_list')
->where('serial_number', $val['serial_number'])
->where('list_id', $val['id'])
->update($seli_edit_data);
timeLog($val['serial_number'], $find_design_order['order_num'], $user_info->install_name, "反馈时间", date('Y-m-d H:i:s'));
}
$order_data=[];
$order_data['order_status'] = 8;
$order_data['update_time'] = date('Y-m-d H:i:s');
$order_data['orders_sertatus']=5;
if($is_over==0){
$order_data['orders_sertatus']=6;
}
// 更改订单信息
$ord_res = DB::table('orders')
->where('id', $find_design_order['id'])
->update($order_data);
if ($deor_res && $ord_res) {
DB::commit();
$str=$order_data['orders_sertatus']==5?'部分反馈':'反馈时间';
sertimeLog($find_design_order['sys_num'], $find_design_order['order_num'], $user_info->install_name, $str, date('Y-m-d H:i:s'),$find_design_order['ser_id']);
return ['ErrorCode' => 1, 'ErrorMessage' => '施工申请完成', 'Data' => []];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => '申请完成失败', 'Data' => []];
}
}
// 施工图片反馈
public static function imageFeedback($request){
// 查询工单表信息
$find_design_order = DB::table('order_list')
->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'serial_number', 'sys_num', 'order_num', 'ord_id', 'service_state', 'lock_state', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['service_state'] != 5) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前工单状态错误!', 'Data' => []];
}
$find_inpe_data = DB::table('install_person')
->where('admin_id', $request['admin_id'])
->where('delet_y', 1)
->select('install_name', 'install_phone')
->first();
$find_inpe_data = objectToArray($find_inpe_data);
// 查询成员账号信息表
$find_adm_data = DB::table('admin')
->where('id', $request['admin_id'])
->select('admin_acc', 'company_name')
->first();
$find_adm_data = objectToArray($find_adm_data);
$image_url=$request['image_url'];
$image_id=$request['image_id'];
$image_type=$request['image_type'];
if($image_url =='undefined'){
return ['ErrorCode' => 500, 'ErrorMessage' => $image_type.'上传失败请重新上传', 'Data' => []];
}
DB::beginTransaction();
$edit_res=true;
// 不是0 则为编辑
if($image_id != 0){
$image_data=Db::table('feedback')
->where('gl_id',$request['id'])
->where('is_delete', 1)
->where('id',$image_id)
->select('feedback_pic')
->first();
if(!empty($image_data)){
$image_path=$image_data->feedback_pic;
// http://3m127.bluearp.com/storage/app/public/image/2022/11/15/166848425637152.jpg
// http://3m127.bluearp.com/storage/image/2022/11/15/166848420917354.jpg
// url 路径里 app/public 被忽略了;
// $image_path=str_replace('storage/image','storage/app/public/image',$image_path);
// $image_path=substr($image_path,strpos($image_path,'storage/app'));
$image_path=substr($image_path,strpos($image_path,'storage'));
// dd(11);
if(file_exists($image_path)){
unlink($image_path);
}
Db::table('feedback')
->where('gl_id',$request['id'])
->where('is_delete', 1)
->where('id',$image_id)
->delete();
}
}
$add_feed=[];
$add_feed['type'] = 1; //图片类型
$add_feed['gl_id'] = $request['id']; //反馈关联id
$add_feed['install_name'] = $find_inpe_data['install_name']; //安装人员姓名
$add_feed['install_phone'] = $find_inpe_data['install_phone']; //安装电话
$add_feed['install_remark'] = ''; //安装备注
$add_feed['install_time'] = date('Y-m-d H:i:s'); //安装时间
$add_feed['admin_id'] = $request['admin_id']; //所属服务中心id
$add_feed['company_name'] = $find_adm_data['company_name']; //服务中心名称
$add_feed['feedback_status'] = 2; //是否安装
$add_feed['feedback_pic'] = $image_url; //凭证图片
$add_feed['sys_num'] = 'rwfk' . $request['id']; //所属服务中心id
$add_feed['is_type'] = 2; //1微信2第三方
$add_feed['type_name'] = $image_type; //类型名称
$add_feed_id = DB::table('feedback')->insertGetId($add_feed);
if ($add_feed_id && $edit_res) {
DB::commit();
return ['ErrorCode' => 1, 'ErrorMessage' => '图片回传成功', 'Data' => ['feed_id'=>$add_feed_id]];
} else {
DB::rollback();
return ['ErrorCode' => 500, 'ErrorMessage' => $add_feed_id.'图片回传失败'.$edit_res, 'Data' => []];
}
}
// 施工时 车牌车架号反馈
public static function LicenseFeedback($request){
// 查询工单表信息
$find_design_order = DB::table('orders')->where('id', $request['id'])
->where('is_delete', 1)
->select('id', 'sys_num', 'order_num', 'order_status', 'lock_type','orders_sertatus', 'ser_id', 'p_id')
->first();
// 判断是否已派单
if (empty($find_design_order)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到订单', 'Data' => []];
}
$find_design_order = objectToArray($find_design_order);
if ($find_design_order['orders_sertatus'] != 5) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单状态错误!', 'Data' => []];
}
if ($find_design_order['lock_type'] != 1) {
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '当前服务单已锁定,无法反馈!', 'Data' => []];
}
$license_plate=$request['license_plate'];
if($license_plate != ''){
$repeat_res = DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('is_delete', 1)
->where('id','<>',$request['gd_id'])
->where('license_plate',$license_plate)
->select('id')
->get()
->toArray();
if(!empty($repeat_res)){
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '车牌/车架号填写重复', 'Data' => []];
}
}
$res=DB::table('order_list')
->where('sys_num', $find_design_order['sys_num'])
->where('is_delete', 1)
->where('id',$request['gd_id'])
->update(['license_plate'=>(string)$license_plate,'update_time'=>date('Y-m-d H:i:s')]);
if($res){
return ['ErrorCode' => 1, 'ErrorMessage' => '回传车架号成功', 'Data' => []];
}else{
return ['ErrorCode' => ErrorInc::BUSINESS_FORBID, 'ErrorMessage' => '保存车架号失败', 'Data' => []];
}
}
// 获取工单反馈信息
public static function getFeedback($request)
{
// 查询服务单表信息
$orders_data = DB::table('orders')
->where('id', $request['id'])
->where('is_delete', 1)
->select('id','sys_num')
->first();
if (empty($orders_data)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到服务单', 'Data' => []];
}
// 获取所有的工单数据
$order_list = DB::table('order_list')
->where('sys_num', $orders_data->sys_num)
->where('is_delete', 1)
->select('id','serial_number',"sys_num", 'license_plate','service_state','orli_reject')
->orderBy('service_state')
->get();
if (empty($order_list)) {
return ['ErrorCode' => ErrorInc::DATA_EMPTY, 'ErrorMessage' => '未查询到工单', 'Data' => []];
}
$order_list = objectToArray($order_list);
$no_pic=[];
$no_pic['gl_id'] = 0;
$no_pic['feedback_pic'] = config('apisystem.HTTP_URL') . 'image/icon/webapp_no_pictures.png';
$no_pic['type_name'] = '暂无图片';
foreach ($order_list as $key => $val) {
// 查询反馈信息
$list_data = DB::table('feedback')
->where('gl_id',$val['id'])
->where('is_delete', 1)
->select("id",'gl_id', 'feedback_pic', 'type_name')
->orderBy('type_name','asc')
->get()->toArray();
if (empty($list_data)) {
$list_data = [$no_pic];
}
$order_list[$key]['list_data']=$list_data;
}
return ['ErrorCode' => 1, 'ErrorMessage' => '获取信息成功', 'Data' => $order_list];
}
// 获取技师
public static function getInstallPerson($request)
{
// 查询工单表信息
$find_inpe_data = InstallPerson::where('delet_y', 1)
->where('admin_id', $request['admin_id'])
->where('install_is_type', 1) //状态:1启用2停用
->where(function ($query) use ($request) {
if (!empty($request['install_name'])) {
$query->where('check_code', 'like', '%' . $request['install_name'] . '%')
->orWhere('install_name', 'like', '%' . $request['install_name'] . '%');
}
})
->select('id', 'check_code', 'install_name')
->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_inpe_data];
}
// 获取标签
public static function getLabel($request)
{
// 查询工单表信息
$find_sety_data = DB::table('setmoney_type')
->where('lt_parent_id', 694)
->where('lt_statues', 1)
->where(function ($query) use ($request) {
if (!empty($request['sety_name'])) {
$query->where('sety_name', 'like', '%' . $request['sety_name'] . '%');
}
})
->select('sety_id', 'sety_name')
->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_sety_data];
}
// 获取操作记录
public static function operatingRecord($request)
{
// 查询操作表信息
$find_data = DB::table('orderserver_time')
->where('serial_number', $request['serial_number'])
->where('ser_id', $request['admin_id'])
->select('create_time', 'is_type')
->orderby('id', 'desc')
->get()->toArray();
return ['ErrorCode' => 1, 'ErrorMessage' => '获取成功', 'Data' => $find_data];
}
// 订单操作时间
public static function operating_time($num,$type,$time,$order_num,$session){
$data['serial_number']=$num;
$data['create_name']=$session['install_name'];
$data['is_type']=$type;
$data['create_time']=$time;
$data['order_num']=$order_num;
$result = OrderTime::insert($data);
if($result){
return 1;
}else{
return 2;
}
}
//添加时间戳
public static function add_thistory ($number,$timetype,$time,$ser_id,$type,$session){
if($type==1){
$poss[$timetype]=strtotime($time);
$poss['tih_serid']=$ser_id;
$poss['tih_number']=$number;
$poss['company_type']=$session['install_name'];
DB::table('time_history')->insert($poss);
}else{
$poss[$timetype]=strtotime($time);
DB::table('time_history')->where("tih_number",$number)->update($poss);
}
}
/**|---------------------------------------------------------------------------------
* @name 同步施工节点
* @param string $coordinate 坐标
* @param string $line_state 节点状态
* @param string $line_serm 工单号
* @param string $line_sysnum 系统单号
* @param string $line_number 单号
* @retrun \Illuminate\Http\JsonResponse /multitype:array
* @author dou 2024/9/11 0:45
* |---------------------------------------------------------------------------------
*/
public static function updateLineSrate ( $coordinate , $line_state , $line_serm , $line_sysnum , $line_number ){
$install_line = InstallLine::where("line_serm",$line_serm)->first();
switch ( $line_state ){
case 2:
$line['line_contact'] = $coordinate;
$line['line_contact_time'] = date("Y-m-d H:i:s");
break;
case 3:
$line['line_start'] = $coordinate;
$line['line_start_time'] = date("Y-m-d H:i:s");
break;
case 4:
$line['line_arrive'] = $coordinate;
$line['line_arrive_time'] = date("Y-m-d H:i:s");
break;
case 5:
$line['line_task'] = $coordinate;
$line['line_task_time'] = date("Y-m-d H:i:s");
break;
case 6:
$line['line_end'] = $coordinate;
$line['line_end_time'] = date("Y-m-d H:i:s");
break;
default:
return false;
break;
}
$line['line_lasttime'] = date("Y-m-d H:i:s");
$line['line_state'] = $line_state;
if(empty($install_line)){
$line['line_serm'] = $line_serm;
$line['line_sysnum'] = $line_sysnum;
$line['line_number'] = $line_number;
$line['line_serm'] = $line_serm;
$res = InstallLine::insert($line);
}else{
$line_states = $line_state-1;
if($line_states < $install_line['line_state']){
return false;
}else{
$res = InstallLine::where("line_serm",$line_serm)->update($line);
}
}
return $res;
}
#计算奖惩金额以及评分
public static function calculates($dou,$orderListArr,$supply_price,$manhourfee,$session){
#商品供货金额
$money['sem_slid'] = $dou;
$money['sem_synum'] = $orderListArr['sys_num'];
$money['sem_price'] = $manhourfee;
$money['sem_creacter'] = $session['install_name'];
$money['sem_type'] = 1;
$money['add_time'] = date("Y-m-d H:i:s");
SettlementMoney::insert($money);
// #开始计算奖惩金额以及评分
// $payout_time = OrderTime::where('serial_number',$orderListArr['serial_number'])
// ->where('is_type','起始时间')
// ->orderBy('id','DESC')
// ->value('create_time');//获取奖罚起始时间
// $zero1 = time();
// $zero2 = strtotime($payout_time);
// $guonian = ($zero1-$zero2)/60;
// #计算评分
// if($guonian<=5){
// $score['orsc_grade'] = 5;
// }if($guonian>5 && $guonian<=10){
// $score['orsc_grade'] = 2;
// }if($guonian>10){
// $score['orsc_grade'] = 1;
// }
// $score['orsc_sernum'] = $orderListArr['serial_number'];
// $score['orsc_slid'] = $dou;
// $score['orsc_creacter'] = $session['install_name'];
// $score['orsc_type'] = 1;
// DB::table("order_score")->insert($score);
// //默认生成平台评分十分
// $scoreq['orsc_grade'] = 5;
// $scoreq['orsc_sernum'] = $orderListArr['serial_number'];
// $scoreq['orsc_slid'] = $dou;
// $scoreq['orsc_creacter'] = $session['install_name'];
// $scoreq['orsc_type']=2;
// DB::table("order_score")->insert($score);
}
}
......@@ -46,7 +46,7 @@ class DealPicService extends Service{
// 上传的是视频
$path_type_name = 'video';//文件夹名
} else {
return ['code'=>500, 'msg'=>'不支持的上传类型', 'data'=>''];
return ['code'=>500, 'msg'=>'不支持的上传类型'.$client_file_type, 'data'=>''];
}
//定义文件名
......
<?php
/**
|--------------------------------------------------------------------------
* 订单扣费
|--------------------------------------------------------------------------
| 派单的时候扣运营商(开店铺的填写订单)的,完成的时候扣经销商(地区代理,施工)
*/
namespace App\Services;
use App\Factory\OrderFactory;
use App\Models\Admin;
use App\Models\AdminInfor;
use App\Models\AdminToken;
use App\Models\AdminCertificate;
use App\Models\Certification;
use App\Models\ScoresSend;
use BlueCity\Core\Service\Service;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;
class OrderDeductionFeeService extends Service
{
public static $instance;
public $modelMain = null;
public function __construct()
{
if (!$this->modelMain) $this->modelMain = new Admin();
}
/**
* @return mixed
*/
public static function getInstance()
{
if (is_null(static::$instance)) {
static::$instance = new static;
}
return static::$instance;
}
/**
* 订单扣费
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-10
* @param [type] $data [description]
* @return [type] [description]
*/
public static function deductFee($data) {
$find_company_info = DB::table('company')
->where('com_id', $data['company_id'])
->first();
$find_balance = DB::table('admin_recharge')
->where('adre_company_id', $data['company_id'])
->first();
$add_dfee['reo_adm_id'] = $data['adm_id'];
$add_dfee['reo_company_id'] = $data['company_id'];
$add_dfee['reo_order_number'] = $data['order_number'];
$add_dfee['reo_price'] = $data['reo_price'];
$add_dfee['reo_pay_state'] = 1;
$add_dfee['reo_state'] = 1;
$add_dfee['reo_create_time'] = date('Y-m-d H:i:s');
$add_dfee['reo_pay_time'] = date('Y-m-d H:i:s');
$add_dfee['reo_pay_way'] = 1;
$add_dfee['reo_type'] = 2;
$add_dfee['reo_client_type'] = 2;
$update['adre_banlance'] = $find_balance['adre_banlance'] + $data['reo_price'];
if (($update['adre_banlance'] + $find_balance['adre_credit_limit']) <= 0) {
return ['code'=>500, 'msg'=>'余额不足,请充值'];
}
$add_res = DB::table('recharge_order')->insertGetId($add_dfee);
$update_res = DB::table('admin_recharge')
->where('adre_id', $find_balance['adre_id'])
->update($update);
if ($add_res && $update_res) {
return ['code'=>200, 'msg'=>'操作成功'];
}
}
/**
* 插入新的数据获取ID值
* @param array $adminData
*
* @return int $id
*/
public static function insertData(array $adminData) {
return Admin::insertGetId($adminData);
}
/**
* 插入新的数据获取ID值
* @param array $adminData
*
* @return int $id
*/
public static function insertAdminInfo(array $adminData) {
return AdminInfor::insertGetId($adminData);
}
/**
* 插入新的数据获取ID值
* @param array $scoresSend
*
* @return int $id
*/
public static function insertScoresSend(array $scoresSend) {
return ScoresSend::insertGetId($scoresSend);
}
/**
* 插入新的数据获取ID值
* @param array $scoresSend
*
* @return int $id
*/
public static function insertCertification(array $certification) {
return Certification::insertGetId($certification);
}
/**
* 获取订单列表
* @param array $params
* @param array $columns
* @return array|mixed
*/
public static function getAdmins($params, $columns = ['id', 'company_name'])
{
$db = new Admin();
return CommonService::getMysqlData($db, $params,$columns,['id'=>'desc']);
}
/**获取admin详细内容
*
* @param int $ID ID
*
* @return array|mixed
*/
public function getAdminByID($ID)
{
return Admin::where('id',$ID)->first();
}
/**获取admin详细内容
*
* @param $key
* @param $value
* @param $select
* @param string $type
*
* @return mixed
*/
public static function getAdminBy($key, $value, $select = [] , $type = 'get')
{
$db = new Admin();
if(in_array($key, ['id'])) {
$type = 'first';
}
if($type == 'first') {
if (count($select) == 1) {
$type = 'value';
}
}
$list = CommonService::getMysqlData($db,[$key=>$value],$select,[],$type);
return $list;
}
}
......@@ -567,10 +567,12 @@ class OrderListService extends Service
}
// }
if ($session['admin_groupnew'] != 7){//管理员可以看全部
if (!in_array($session['admin_groupnew'], [2,3,7])){//管理员可以看全部
$where['gone_order_list.company_id'] = $session['company_id'];
}
if ($session['admin_groupnew'] == 3) {
$where['gone_order_list.agency_id'] = $session['company_id'];
}
$where = CommonService::jointWhere($where);
$page_size = $input['page_size']??10;
......
<?php
namespace App\Services;
use Illuminate\Database\Eloquent\Model;
use BlueCity\Core\Service\Service;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;
use BlueCity\Core\Inc\ErrorInc;
use Illuminate\Support\Facades\Request;
use App\Models\Common;
class PayService extends Service
{
public static $instance;
public $modelMain = null;
public $mainValidator = null;
public function __construct()
{
$this->charset = 'utf8';
}
/**
* @return mixed
*/
public static function getInstance()
{
if (is_null(static::$instance)) {
static::$instance = new static;
}
return static::$instance;
}
protected $appId;
protected $notifyUrl;
protected $charset;
//私钥值
protected $rsaPrivateKey;
protected $totalFee;
protected $outTradeNo;
protected $orderName;
public function setAppid($appid)
{
$this->appId = $appid;
}
public function setNotifyUrl($notifyUrl)
{
$this->notifyUrl = $notifyUrl;
}
public function setRsaPrivateKey($saPrivateKey)
{
$this->rsaPrivateKey = $saPrivateKey;
}
public function setTotalFee($payAmount)
{
$this->totalFee = $payAmount;
}
public function setOutTradeNo($outTradeNo)
{
$this->outTradeNo = $outTradeNo;
}
public function setOrderName($orderName)
{
$this->orderName = $orderName;
}
/**
* 发起订单
* @return array
*/
public function aliPay()
{
//请求参数
$requestConfigs = array(
'out_trade_no'=>$this->outTradeNo,
'total_amount'=>$this->totalFee, //单位 元
'subject'=>$this->orderName, //订单标题
'timeout_express'=>'2h' //该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
);
$commonConfigs = array(
//公共参数
'app_id' => $this->appId,
'method' => 'alipay.trade.precreate', //接口名称
'format' => 'JSON',
'charset'=>$this->charset,
'sign_type'=>'RSA2',
'timestamp'=>date('Y-m-d H:i:s'),
'version'=>'1.0',
'notify_url' => $this->notifyUrl,
'biz_content'=>json_encode($requestConfigs),
);
$commonConfigs["sign"] = $this->generateSign($commonConfigs, $commonConfigs['sign_type']);
//沙箱网关接口,正式版网关接口自行修改
$result = $this->curlPost('https://openapi.alipay.com/gateway.do',$commonConfigs);
return json_decode($result,true);
}
public function generateSign($params, $signType = "RSA") {
return $this->sign($this->getSignContent($params), $signType);
}
protected function sign($data, $signType = "RSA") {
$priKey=$this->rsaPrivateKey;
$res = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap($priKey, 64, "\n", true) .
"\n-----END RSA PRIVATE KEY-----";
($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
if ("RSA2" == $signType) {
openssl_sign($data, $sign, $res, version_compare(PHP_VERSION,'5.4.0', '<') ? SHA256 : OPENSSL_ALGO_SHA256); //OPENSSL_ALGO_SHA256是php5.4.8以上版本才支持
} else {
openssl_sign($data, $sign, $res);
}
$sign = base64_encode($sign);
return $sign;
}
/**
* 校验$value是否非空
* if not set ,return true;
* if is null , return true;
**/
protected function checkEmpty($value) {
if (!isset($value))
return true;
if ($value === null)
return true;
if (trim($value) === "")
return true;
return false;
}
public function getSignContent($params) {
ksort($params);
$stringToBeSigned = "";
$i = 0;
foreach ($params as $k => $v) {
if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
// 转换成目标字符集
$v = $this->characet($v, $this->charset);
if ($i == 0) {
$stringToBeSigned .= "$k" . "=" . "$v";
} else {
$stringToBeSigned .= "&" . "$k" . "=" . "$v";
}
$i++;
}
}
unset ($k, $v);
return $stringToBeSigned;
}
/**
* 转换字符集编码
* @param $data
* @param $targetCharset
* @return string
*/
function characet($data, $targetCharset) {
if (!empty($data)) {
$fileType = $this->charset;
if (strcasecmp($fileType, $targetCharset) != 0) {
$data = mb_convert_encoding($data, $targetCharset, $fileType);
//$data = iconv($fileType, $targetCharset.'//IGNORE', $data);
}
}
return $data;
}
public function curlPost($url = '', $postData = '', $options = array())
{
if (is_array($postData)) {
$postData = http_build_query($postData);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置cURL允许执行的最长秒数
if (!empty($options)) {
curl_setopt_array($ch, $options);
}
//https请求 不验证证书和host
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}
<?php
namespace App\Services;
use Illuminate\Database\Eloquent\Model;
use BlueCity\Core\Service\Service;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use App\Models\Common;
use Illuminate\Support\Facades\DB;
use BlueCity\Core\Inc\ErrorInc;
use App\Http\Models\Services\ImageUpload;
use App\Models\OperationLog;
use Illuminate\Http\Request;
class WarehouseService extends Service
{
public static $instance;
public $modelMain = null;
public $mainValidator = null;
public function __construct()
{
}
/**
* @return mixed
*/
public static function getInstance()
{
if (is_null(static::$instance)) {
static::$instance = new static;
}
return static::$instance;
}
/**
* 减少库存
* @authors ldj
* @email 909490343@qq.com
* @date 2024-09-11
* @param [type] $data [description]
* @return [type] [description]
*/
public static function chargeWareGoodsNum($data) {
if (empty($data['ware_id'])) {
return ['Data' =>'', 'ErrorMessage' => '请选择仓库', 'ErrorCode' => 2];
}
if (empty($data['goods_data'])) {
return ['Data' =>'', 'ErrorMessage' => '请选择商品', 'ErrorCode' => 2];
}
$goods_data = $data['goods_data'];
foreach ($goods_data as $key => $value) {
if (empty($value['goods_num'])) {
return ['Data' =>'', 'ErrorMessage' => '请选择数量', 'ErrorCode' => 2];
}
$find_goods = DB::table('pj_goods')
->where('pg_id', $value['goods_id'])
->first();
if (empty($find_goods)) {
return ['Data' =>'', 'ErrorMessage' => '未查询到此商品', 'ErrorCode' => 2];
}
if ($find_goods['is_delect'] == 2) {
return ['Data' =>'', 'ErrorMessage' => '此商品已停用', 'ErrorCode' => 2];
}
$find_data = DB::table('ware_goods')
->where('wago_ware_id', $data['ware_id'])
->where('wago_goo_id', $value['goods_id'])
->first();
if (empty($find_data)) {
$add_data['wago_company_id'] = $session['company_id'];
$add_data['wago_ware_id'] = $data['ware_id'];
$add_data['wago_goo_id'] = $value['goods_id'];
$add_data['wago_stock_num'] = $value['goods_num'];
$add_res = DB::table('ware_goods')->insertGetId($add_data);
$goio_old_num = 0;
$goio_new_num = $value['goods_num'];
} else {
$update['wago_stock_num'] = $find_data['wago_stock_num'] + $value['goods_num'];
$add_res = DB::table('ware_goods')
->where('wago_id', $find_data['wago_id'])
->update($update);
$add_res = $find_data['wago_id'];
$goio_old_num = $find_data['wago_stock_num'];
$goio_new_num = $update['wago_stock_num'];
}
$add_record['goio_ware_id'] = $data['ware_id'];
$add_record['goio_sys_num'] = $data['sys_num'];
$add_record['goio_serial_number'] = $data['serial_number'];
$add_record['goio_wago_id'] = $add_res;
$add_record['goio_goo_id'] = $value['goods_id'];
$add_record['goio_num'] = $value['goods_num'];
$add_record['goio_old_num'] = $goio_old_num;
$add_record['goio_new_num'] = $goio_new_num;
$add_record['goio_type'] = '减少库存';
$add_record_res = DB::table('goods_inout')->insert($add_record);
}
return ['Data' =>'', 'ErrorMessage' => '成功', 'ErrorCode' => 1];
}
/**
* 微信电商收付通API V3
* 不同的商户,对应的微信支付平台证书是不一样的,平台证书会周期性更换。建议商户定时通过API下载新的证书,不要依赖人工更换证书。
* 微信支付的平台证书序列号位于HTTP头Wechatpay-Serial。验证签名前,请商户先检查序列号是否跟商户当前所持有的微信支付平台证书的序列号一致。
* 生成签名的serial_no是网站上面的证书的序列号。而HTTP头Wechatpay-Serial以post方式带上的serial_no是实时获取的serial_no。
* 后期可以做缓存serial_no,并且缓存新证书内容,不需要每次都获取且保存文件。
* 如果不一致,请重新获取证书。否则,签名的私钥和证书不匹配,将无法成功验证签名。
*/
// get方式 提交 body不参与签名
public static function _Getresponse($url, $body = '')
{
$methed = 'GET';
$date = time();
$nonce = self::createNoncestr();
$sign = self::sign($url, $methed, $date, $nonce, $body); //$http_method要大写
$header[] = 'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36';
$header[] = 'Accept:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$r = self::_requestGet($url, $body, $header);
return $r;
}
public static function _Postresponse($url, $body)
{
$methed = 'POST';
$date = time();
if (is_array($body)) {
$body = json_encode($body);
}
$nonce = self::createNoncestr();
$sign = self::sign($url, $methed, $date, $nonce, $body);
$serial_nos = self::certificates();
$header[] = 'User-Agent:233';
$header[] = 'Accept:application/json';
$header[] = 'Content-Type:application/json';
$header[] = 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $sign;
$header[] = 'Wechatpay-Serial:' . $serial_nos;
$r = self::_requestPost($url, $body, $header);
return $r;
}
/**
* [_requestGet CURL GET请求]
* @param [type] $url [请求目标]
* @param [type] $meta [请求参数]
* @param [type] $header [头部参数]
* @return [type] [结果返回]
*/
private static function _requestGet($url, $meta, $header = array(), $referer = '', $timeout = 30)
{
$ch = curl_init();
//设置抓取的url
curl_setopt($ch, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//执行命令
$response = curl_exec($ch);
if ($error = curl_error($ch)) {
curl_close($ch);
throw new WxPayv3Exception($error);
}
curl_close($ch);
return $response;
}
/**
* [_requestPost CURL POST请求]
* @param [type] $url [请求目标]
* @param [type] $data [请求参数]
* @param array $header [头部参数]
* @param string $referer [referer]
* @param integer $timeout [超时时间:单位秒]
* @return [type] [结果返回]
*/
private static function _requestPost($url, $data, $header = array(), $referer = '', $timeout = 30)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//避免https 的ssl验证
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
// 模拟来源
curl_setopt($ch, CURLOPT_REFERER, $referer);
$response = curl_exec($ch);
if ($error = curl_error($ch)) {
curl_close($ch);
throw new WxPayv3Exception($error);
}
curl_close($ch);
return $response;
}
/**|---------------------------------------------------------------------------------
* @name 模拟post请求
* @param string $url 请求链接
* @param array $param 请求参数
* @param array $header 请求头
* @retrun multitype:array
* @author dou 2021/8/9 19:35
* |---------------------------------------------------------------------------------
*/
public static function requestPost($url,$param,$header='') {
/*$header = array(
'Content-Type: application/json',
);*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if($header!=''){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// https 请求//如果地址是https协议,且CURLOPT_SSL_VERIFYPEER和CURLOPT_SSL_VERIFYHOST打开了,则需要加载证书
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
if (is_array($param) && 0 < count($param)) {
$postMultipart = false;
foreach ($param as $k => $v) {
if ('@' == substr($v, 0, 1)) {
$postMultipart = true;
break;
}
}
unset($k, $v);
if ($postMultipart) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);// post传输数据
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));
}
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);// post传输数据
}
$response = curl_exec($ch);
curl_close($ch);
return trim($response);
}
/**[sign 签名]
* [sign 签名]
* @param [type] $url [请求目标]
* @param [type] $http_method [请求方式 GET POST PUT]
* @param [type] $timestamp [时间戳]
* @param [type] $nonce [随机串]
* @param [type] $body [报文 GET请求时可以为空]
* @param [type] $mch_private_key [api 密钥]
* @param [type] $merchant_id [发起请求的商户(包括直连商户、服务商或渠道商)的商户号mchid]
* @param [type] $serial_no [证书序列号]
* @return [type] [返回为签名串]
*/
public static function sign($url, $http_method, $timestamp, $nonce, $body = '')
{
if (!in_array('sha256WithRSAEncryption', \openssl_get_md_methods(true))) {
throw new WxPayv3Exception("当前PHP环境不支持SHA256withRSA");
}
//发起请求的商户(包括直连商户、服务商或渠道商)的商户号mchid
// $merchant_id = Config::MCHID;
$merchant_id = config('apisystem.MCHID');
//商户API证书序列号
// $serial_no = Config::SERIAL_NO;
$serial_no = config('apisystem.SERIAL_NO');
//获取私钥
// $mch_private_key = self::getPrivateKey(getcwd() . Config::SSLKEY_PATH); //商户私钥
$mch_private_key = self::getPrivateKey(getcwd() . config('apisystem.SSLKEY_PATH')); //商户私钥
$url_parts = parse_url($url);
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
if ($http_method == 'GET') {
$body = '';
}
$message =
$http_method . "\n" .
$canonical_url . "\n" .
$timestamp . "\n" .
$nonce . "\n" .
$body . "\n";
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
$sign = base64_encode($raw_sign);
$token = sprintf(
'mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$merchant_id,
$nonce,
$timestamp,
$serial_no,
$sign
);
return $token;
}
/**
* 吊起支付 封裝
* @param string appid 微信公众号的APPID或者小程序的appid
* @param string prepay_id 合单支付返回的prepay_id
*/
public static function _PayJson($appid, $prepay_id)
{
$timestamp = (string)time();
$nonceStr = self::createNoncestr();
$package = 'prepay_id=' . $prepay_id;
$paySign = self::paySign($appid, $timestamp, $nonceStr, $package);
$data = [
'appId' => $appid,
'timeStamp' => $timestamp,
'nonceStr' => $nonceStr,
'package' => $package,
'signType' => 'RSA',
'paySign' => $paySign
];
return json_encode($data);
}
/**
* 支付pay计算签名
* @param string appid 微信公众号的APPID或者小程序的appid
* @param string timestamp 时间戳
* @param string nonceStr 随机字符串
* @param string body 签名主体内容 prepay_id=wx_12121
*/
private static function paySign($appid, $timestamp, $nonceStr, $body)
{
if (!in_array('sha256WithRSAEncryption', \openssl_get_md_methods(true))) {
throw new WxPayv3Exception("当前PHP环境不支持SHA256withRSA");
}
// $mch_private_key = self::getPrivateKey(getcwd() . Config::SSLKEY_PATH); //商户私钥
$mch_private_key = self::getPrivateKey(getcwd() . config('apisystem.SSLKEY_PATH')); //商户私钥
$message =
$appid . "\n" .
$timestamp . "\n" .
$nonceStr . "\n" .
$body . "\n";
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
$paySign = base64_encode($raw_sign);
return $paySign;
}
//获取私钥
private static function getPrivateKey($filepath)
{
return openssl_get_privatekey(file_get_contents($filepath));
}
//加载证书 公钥
public static function getCertificate($filepath)
{
return openssl_x509_read(file_get_contents($filepath));
}
//作用:产生随机字符串,不长于32位
private static function createNoncestr($length = 32)
{
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
/**
* [getEncrypt V3敏感信息进行加密]
* 使用的是公钥 ok
* @param string str要加密的内容
*/
public static function getEncrypt($str)
{
//$public_key_path = '证书地址'; //看情况使用证书, 个别接口证书 使用的是 平台证书而不是 api证书
// $mch_public_key = self::getCertificate(getcwd() . Config::SSLCERT_PATH);
// $mch_public_key = self::getCertificate(getcwd() . config('apisystem.SSLCERT_PATH'));
// var_dump(getcwd() . config('apisystem.SSLCERT_PATH'));die;
$mch_public_key = self::getCertificate(getcwd() . '/pay/weixin/cert/apiclient_20220622_cert.pem');
$encrypted = '';
if (openssl_public_encrypt($str, $encrypted, $mch_public_key, OPENSSL_PKCS1_OAEP_PADDING)) {
//base64编码
$sign = base64_encode($encrypted);
} else {
throw new WxPayv3Exception('加密encrypt failed');
}
return $sign;
}
/**
* [getPrivateEncrypt V3敏感信息进行解密]
* @param string str 需要解密的秘闻 ok
*/
public static function getPrivateEncrypt($str)
{
$result = false;
$str = base64_decode($str);
$mch_private_key = self::getPrivateKey(getcwd() . Config::SSLKEY_PATH);
if (openssl_private_decrypt($str, $result, $mch_private_key, OPENSSL_PKCS1_OAEP_PADDING)) {
return $result;
} else {
throw new WxPayv3Exception('解密Encrypt failed');
}
}
/**
* [decryptToString V3 证书和回调报文解密]
* @param stingr $aesKey V3签名
* @param string $associatedData 附加数据包
* @param string $nonceStr 加密使用的随机串初始化向量)
* @param string $ciphertext Base64编码后的密文
*
* @return string|bool Decrypted string on success or FALSE on failure
*/
public static function decryptToString($associatedData, $nonceStr, $ciphertext)
{
// $aesKey = Config::APPKERV3;
$aesKey = config('apisystem.APPKERV3');
if (strlen($aesKey) != 32) {
throw new WxPayv3Exception('无效的ApiV3Key,长度应为32个字节');
}
$ciphertext = \base64_decode($ciphertext);
if (strlen($ciphertext) <= 16) {
throw new WxPayv3Exception('无效的数据密文,长度应为16个字节以上');
}
// ext-sodium (default installed on >= PHP 7.2)
if (
function_exists('\sodium_crypto_aead_aes256gcm_is_available') &&
\sodium_crypto_aead_aes256gcm_is_available()
) {
return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);
}
// ext-libsodium (need install libsodium-php 1.x via pecl)
if (
function_exists('\Sodium\crypto_aead_aes256gcm_is_available') &&
\Sodium\crypto_aead_aes256gcm_is_available()
) {
return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $aesKey);
}
// openssl (PHP >= 7.1 support AEAD)
if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) {
$ctext = substr($ciphertext, 0, -16);
$authTag = substr($ciphertext, -16);
return \openssl_decrypt(
$ctext,
'aes-256-gcm',
$aesKey,
\OPENSSL_RAW_DATA,
$nonceStr,
$authTag,
$associatedData
);
}
throw new WxPayv3Exception('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php');
}
/**
* 获取毫秒级别的时间戳
*/
private static function getMillisecond()
{
$time = explode(" ", microtime());
$time = $time[1] . ($time[0] * 1000);
$time2 = explode(".", $time);
$time = $time2[0];
return $time;
}
/**
* [certificates 保存获取的平台证书,且返回证书的序列号serial_no] 缓存一天时间
* @return string serial_no证书的序列号
*/
public static function certificates()
{
if (file_exists(getcwd() . '/vendor/wechat3/cert/serial_no.txt')) {
if ($serial_nos = file_get_contents(getcwd() . '/vendor/wechat3/cert/serial_no.txt')) {
if ($serial_nos) {
$serial_nos = json_decode($serial_nos,true);
if (time() < $serial_nos['time']) { //如果 1天缓存未过期,直接使用。
return $serial_nos['serial_no'];
}
}
}
}
$url = 'https://api.mch.weixin.qq.com/v3/certificates';
$r = self::_Getresponse($url);
$r = json_decode($r, true);
if (isset($r['code'])) {
return $r;
}
$r = $r['data'];
if (is_array($r)) {
$associatedData = $r[0]['encrypt_certificate']['associated_data'];
$nonceStr = $r[0]['encrypt_certificate']['nonce'];
$ciphertext = $r[0]['encrypt_certificate']['ciphertext'];
try {
$data1 = self::decryptToString($associatedData, $nonceStr, $ciphertext);
$serial_no = $r[0]['serial_no'];
file_put_contents(getcwd() . '/pay/weixin/cert/'.'apiclient_'.date('Ymd').'_cert'.'.pem', $data1);
unset($serial_nos);
$serial_nos = [
'time' => time() + 24 * 3600,
'serial_no' => $serial_no
];
file_put_contents(getcwd() . '/pay/weixin/cert/serial_no.txt', json_encode($serial_nos));
} catch (WxPayv3Exception $th) {
throw $th;
}
}
return $serial_no;
}
// 统一下单
public static function transactionsjsapi ($request)
{
if (!isset($request['weus_openid'])) {
$request['weus_openid'] = DB::table('weixin_user')
->where('weus_id', $request['weus_id'])
->value('weus_openid');
}
// 查询小程序订单的数据
$find_data = DB::table('order as ord')
->leftJoin('order_goods as orgo', 'orgo.orgo_ord_id', '=', 'ord.ord_id')
->where('ord_id', $request['ord_id'])
->select('ord_id', 'ord_order_number', 'ord_actual_price', 'ord_order_price', 'ord_state', 'orgo_goo_name', 'ord_shop_id')
->first();
if (empty($find_data)) {
return ['code'=>500, 'msg'=>'请选择支付订单', 'data'=>''];
}
if ($find_data->ord_order_price == 0) {
DB::beginTransaction();
$find_order = DB::table('order')
->leftjoin('order_client', 'ord_id', '=', 'orcl_ord_id')
->where('ord_id', $request['ord_id'])
->first();
//修改订单信息
$update_data['ord_state'] = 2;
$update_data['ord_pay_state'] = 1;
$update_data['ord_update_time'] = date('Y-m-d H:i:s');
$update_data['ord_settlement_time'] = date('Y-m-d H:i:s');
$update_res = DB::table('order')
->where('ord_id', $request['ord_id'])
->update($update_data);
// 修改已售数量
$pait_data = DB::table('order as o')
->leftjoin('order_goods as orgo', 'orgo.orgo_ord_id', '=', 'o.ord_id')
->leftjoin('package_items as pait', 'pait.pait_id', '=', 'orgo.orgo_goo_id')
->where('ord_id', $request['ord_id'])
->where('orgo_goo_type', 3)
->select('pait_id', 'pait_sell_number', 'pait_saleable_quantity', 'ord_type')
->first();
if ($pait_data) {
$update_pait_data['pait_sell_number'] = $pait_data->pait_sell_number + 1;
$update_pait_data['pait_saleable_quantity'] = $pait_data->pait_saleable_quantity - 1;
if ($pait_data->pait_saleable_quantity - 1 == 0) {
$update_pait_data['pait_state'] = 2;//1上架2下架
}
$update_pait_data['pait_update_time'] = date('Y-m-d H:i:s');
$update_pait = DB::table('package_items')
->where('pait_id', $pait_data->pait_id)
->update($update_pait_data);
} else {
$update_pait = true;
}
if ($find_order) {
if ($find_order->ord_service_type == 4) {//会员卡订单添加会员会员卡
$find_orgo_data = DB::table('order_goods')
->where('orgo_ord_id', $find_order->ord_id)
->first();
if ($find_orgo_data) {
$find_vica_data = DB::table('vip_card')
->where('vica_name', $find_orgo_data->orgo_goo_name)
->first();
if ($find_vica_data) {
$myvi_num = 'HYK'.time().rand(10000,99999);
$data['myvi_num'] = $myvi_num;//会员卡编号
$data['myvi_create_adm_id'] = $find_order->ord_create_id;
$data['myvi_shop_id'] = $find_order->ord_shop_id;
$data['myvi_adm_id'] = $find_order->orcl_client_id;
$data['myvi_surplus_times'] = $find_vica_data->vica_num; //剩余次数
$data['myvi_all_times'] = $find_vica_data->vica_num; //总次数
$data['myvi_long_term'] = $find_vica_data->vica_long_term; //是否长期1是2否
$data['myvi_carnum'] = $find_order->orcl_car_num; //绑定车牌
$data['myvi_sepr_id'] = $find_vica_data->vica_sepr_id; //服务项目id
$data['myvi_sepr_name'] = $find_vica_data->vica_sepr_name; //服务项目名称
$data['myvi_name'] = $find_vica_data->vica_name; //会员卡名称
$data['myvi_explain'] = $find_vica_data->vica_instructions; //会员卡使用说明
$data['myvi_vica_id'] = $find_vica_data->vica_id; //会员卡id
$data['myvi_create_time'] = date('Y-m-d H:i:s');
if ($find_vica_data->vica_long_term == 2) {//是否长期1是2否
$data['myvi_effective_date'] = $find_vica_data->vica_effective_date; //有效天数
$data['myvi_end_time'] = date('Y-m-d', strtotime(date('Y-m-d').'23:59:59') + ($find_vica_data->vica_effective_date)*60*60*24).' 23:59:59';
} else {
$data['myvi_end_time'] = date('Y-m-d', time() + 99999*60*60*24);
}
$myvi_id = DB::table('myvip')->insertGetId($data);
} else {
$myvi_id = true;
}
} else {
$myvi_id = true;
}
} else {
$myvi_id = true;
}
} else {
$myvi_id = true;
}
if ($update_res && $update_pait && $myvi_id) {
DB::commit();
return response()->json(['code'=>200, 'message'=>'成功']);
} else {
DB::rollBack();
return response()->json(['code'=>200, 'message'=>'成功']);
}
}
if ($find_data->ord_shop_id) {
$shop_data = DB::table('shop')
->where('shop_id', $find_data->ord_shop_id)
->select('shop_id', 'shop_machid')
->first();
if ($shop_data->shop_machid) {
$XCX_MCHID = strval($shop_data->shop_machid);
} else {
$XCX_MCHID = config('apisystem.XCX_MCHID');
}
} else {
return ['code'=>500, 'msg'=>'请选择门店', 'data'=>''];
}
$url = 'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi';
$settle_info =
[
'profit_sharing' => false, //是否分账,与外层profit_sharing同时存在时,以本字段为准。 示例值:true
];
$description = '半径服务-'.$find_data->orgo_goo_name;
$out_trade_no = $find_data->ord_order_number;
$amount = [
'total' => $find_data->ord_order_price, //订单总金额,单位为分。
'currency' => 'CNY' //CNY:人民币,境内商户号仅支持人民币。
];
$payer = [
'sub_openid' => $request['weus_openid'] //用户在子商户appid下的唯一标识。若传sub_openid,那sub_appid必填
];
// $notify_url = 'https://xm.bluearp.com/index.php/api/u1/Pay/notifyPay';
$notify_url = config('apisystem.server_name_https').'/index.php/api/u1/Pay/notifyPay';
$paramData = [
//服务商应用ID
'sp_appid' => config('apisystem.COMBINE_APPID'), //合单发起方的appid 示例值:wxd678efh567hg6787
//服务商户号
'sp_mchid' => config('apisystem.MCHID'), //合单发起方商户号。示例值:1900000109
'sub_appid' => config('apisystem.XCX_APPID'), //二级商户应用ID
// 'sub_mchid' => config('apisystem.XCX_MCHID'), //二级商户号
'sub_mchid' => $XCX_MCHID, //二级商户号
'description' => $description,
'out_trade_no' => $out_trade_no,//商户订单号
'settle_info' => $settle_info,
'amount' => $amount,
'payer' => $payer,
//交易结束时间
// 'time_expire' => $time_expire,//订单失效时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。示例值:2019-12-31T15:59:60+08:00
//通知地址
'notify_url' => $notify_url, //接收微信支付异步通知回调地址,通知url必须为直接可访问的URL,不能携带参数。格式: URL 示例值:https://yourapp.com/notify
];
$parameters = json_encode($paramData);
return self::_Postresponse($url, $parameters);
}
// 其他小程序统一下单
public static function otherTransactionsJsapi ($request)
{
if (!isset($request['weus_openid'])) {
return ['code'=>500, 'msg'=>'请选择小程序', 'data'=>''];
}
if ($request['XCX_MCHID']) {
$XCX_MCHID = $request['XCX_MCHID'];
} else {
$XCX_MCHID = config('apisystem.XCX_MCHID');
}
$url = 'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi';
if ($request['profit_sharing'] == 1) {
$settle_info =
[
'profit_sharing' => true, //是否分账,与外层profit_sharing同时存在时,以本字段为准。 示例值:true
];
} elseif ($request['profit_sharing'] == 2) {
$settle_info =
[
'profit_sharing' => false, //是否分账,与外层profit_sharing同时存在时,以本字段为准。 示例值:true
];
}
$description = $request['XCX_Name'].'-'.$request['orgo_goo_name'];
$out_trade_no = $request['ord_order_number'];
$amount = [
'total' => (int)$request['ord_order_price'], //订单总金额,单位为分。
'currency' => 'CNY' //CNY:人民币,境内商户号仅支持人民币。
];
$payer = [
'sub_openid' => $request['weus_openid'] //用户在子商户appid下的唯一标识。若传sub_openid,那sub_appid必填
];
// $notify_url = 'https://xm.bluearp.com/index.php/api/u1/Pay/notifyPay';
$notify_url = config('apisystem.server_name_https').'/index.php/api/u1/Pay/otherNotifyPay';
$paramData = [
//服务商应用ID
'sp_appid' => config('apisystem.COMBINE_APPID'), //合单发起方的appid 示例值:wxd678efh567hg6787
//服务商户号
'sp_mchid' => config('apisystem.MCHID'), //合单发起方商户号。示例值:1900000109
// 'sub_appid' => config('apisystem.XCX_APPID'), //二级商户应用ID
'sub_appid' => $request['XCX_APPID'], //二级商户应用ID
// 'sub_mchid' => config('apisystem.XCX_MCHID'), //二级商户号
'sub_mchid' => $XCX_MCHID, //二级商户号
'description' => $description,
'out_trade_no' => $out_trade_no,//商户订单号
'settle_info' => $settle_info,
'amount' => $amount,
'payer' => $payer,
//交易结束时间
// 'time_expire' => $time_expire,//订单失效时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。示例值:2019-12-31T15:59:60+08:00
//通知地址
'notify_url' => $notify_url, //接收微信支付异步通知回调地址,通知url必须为直接可访问的URL,不能携带参数。格式: URL 示例值:https://yourapp.com/notify
];
$parameters = json_encode($paramData);
return self::_Postresponse($url, $parameters);
}
// 请求分账
public static function reqAccount($out_order_no, $transaction_id, $sub_mchid, $receivers,$finish)
{
$url = 'https://api.mch.weixin.qq.com/v3/ecommerce/profitsharing/orders';
$post = [
// 'appid' => Config::COMBINE_APPID,
'appid' => config('apisystem.COMBINE_APPID'),
'out_order_no' => $out_order_no,
'transaction_id' => $transaction_id,
'sub_mchid' => $sub_mchid,
'receivers' => $receivers,
'finish' => $finish
];
$post = json_encode($post);
$ret = self::_Postresponse($url, $post);
return $ret;
}
/**
* 完结分账 post 收付通
* 不需要分账的账单直接把二级商户里面的金额直接解冻给二级商户
* @param string out_order_no 商户分帐单号 唯一 自己生成
* @param string transaction_id 微信支付子单号的流水号
* @param string sub_mchid 电商平台二级商户
* @param string description 描述
*/
public static function finishAccount($out_order_no, $transaction_id, $sub_mchid, $description)
{
$url = 'https://api.mch.weixin.qq.com/v3/ecommerce/profitsharing/finish-order';
$post = [
'sub_mchid' => $sub_mchid,
'transaction_id' => $transaction_id,
'out_order_no' => $out_order_no,
'description' => $description ?: '分账完结'
];
$ret = self::_Postresponse($url, $post);
return $ret;
}
/**
* 退款申请API 收付通
* 备注:交易时间超过一年的订单无法提交退款;每个支付订单的部分退款次数不能超过50次
* @param string sub_mchid 微信支付分配二级商户的商户号
* @param string out_refund_no 商户系统内部的退款单号
* @param string transaction_id 原支付交易对应的微信订单号 子流水号
* @param string out_trade_no 原支付交易对应的商户订单
* @param string refund_fee 子单的申请的退款金额 分
* @param string total_fee 子单的全部金额 分
* @param string notify_url 退款回调地址
* @param string reason 退款原因
* @param string sign 退款单来源 weixin xcx h5 等,后期会涉及到使用
*/
public static function applyRefund($sub_mchid, $out_refund_no, $transaction_id, $out_trade_no, $refund_fee, $total_fee, $notify_url = '', $reason = '', $sign = '')
{
$post = [
'sub_mchid' => $sub_mchid, //二级商户号
// 'sub_appid' => $sub_appid, //二级商户APPID 可空
'sp_appid' => config('apisystem.COMBINE_APPID'),// Config::COMBINE_APPID, //电商平台APPID 可空
'transaction_id' => $transaction_id,
'out_trade_no' => $out_trade_no,
'out_refund_no' => $out_refund_no,
'reason' => $reason,
'amount' => [
'refund' => (int)$refund_fee,
'total' => (int)$total_fee,
'currency' => 'CNY'
],
'notify_url' => $notify_url
];
$url = 'https://api.mch.weixin.qq.com/v3/ecommerce/refunds/apply';
$ret = self::_Postresponse($url, json_encode($post));
return $ret;
}
/**
* 发起订单
* @param float $totalFee 收款总费用 单位元
* @param string $outTradeNo 唯一的订单号
* @param string $orderName 订单名称
* @param string $notifyUrl 支付结果通知url 不要有问号
* @param string $timestamp 订单发起时间
* @return array
*/
public static function createJsBizPackage($totalFee, $outTradeNo, $orderName, $notifyUrl, $timestamp, $config)
{
// $orderName = iconv('GBK','UTF-8',$orderName);
$unified = array(
'appid' => $config['appid'],
'attach' => 'pay', //商家数据包,原样返回,如果填写中文,请注意转换为utf-8
'body' => $orderName,
'mch_id' => $config['mch_id'],
'nonce_str' => self::createNonceStr(),
'notify_url' => $notifyUrl,
'out_trade_no' => $outTradeNo,
'spbill_create_ip' => '127.0.0.1',
'total_fee' => $totalFee, //单位 转为分
'trade_type' => 'NATIVE',
);
$unified['sign'] = self::getSign($unified, $config['key']);
$responseXml = self::curlPost('https://api.mch.weixin.qq.com/pay/unifiedorder', self::arrayToXml($unified));
$unifiedOrder = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($unifiedOrder === false) {
return ['code' => 500, 'msg' => '付款失败', 'data' => ''];
die('parse xml error');
}
if ($unifiedOrder->return_code != 'SUCCESS') {
return ['code' => 500, 'msg' => '付款失败'.$unifiedOrder->return_msg, 'data' => ''];
}
if ($unifiedOrder->result_code != 'SUCCESS') {
return ['code' => 500, 'msg' => '付款失败'.$unifiedOrder->result_code, 'data' => ''];
}
$codeUrl = (array)($unifiedOrder->code_url);
if(!$codeUrl[0]) {
return ['code' => 500, 'msg' => '获取付款码失败', 'data' => ''];
}
$arr = array(
"appId" => $config['appid'],
"timeStamp" => $timestamp,
"nonceStr" => self::createNonceStr(),
"package" => "prepay_id=" . $unifiedOrder->prepay_id,
"signType" => 'MD5',
"code_url" => $codeUrl[0],
);
$arr['paySign'] = self::getSign($arr, $config['key']);
$return_data = $codeUrl[0];
return ['code' => 200, 'msg' => 'success', 'data' => $return_data];
}
public static function notify($request, $config)
{
$postObj = simplexml_load_string($request, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($postObj === false) {
die('parse xml error');
}
if ($postObj->return_code != 'SUCCESS') {
die($postObj->return_msg);
}
if ($postObj->result_code != 'SUCCESS') {
die($postObj->err_code);
}
$arr = (array)$postObj;
unset($arr['sign']);
if (self::getSign($arr, $config['key']) == $postObj->sign) {
$find_order = DB::table('recharge_order')
->where('reo_order_number', $postObj->out_trade_no)
->first();
if ($find_order->reo_pay_state == 1) {
return '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
}
$update_were = DB::table('weixin_record')
->where('out_trade_no', $postObj->out_trade_no)
->update(['were_pay_state'=>2,'were_transaction_id'=>$postObj->transaction_id]);
$update_order = DB::table('recharge_order')
->where('reo_order_number', $postObj->out_trade_no)
->update(['reo_pay_state'=>2,'reo_paid_money'=>$find_order['reo_price'],'reo_pay_way'=>1,'reo_pay_check'=>1, 'reo_pay_time'=>date('Y-m-d H:i:s')]);
$find_data = DB::table('admin_recharge')
->where('adre_company_id', $find_order['reo_company_id'])
->first();
if ($find_data) {
$adre_banlance = $find_data['adre_banlance'] + $find_order['reo_price'];
$update_res = DB::table('admin_recharge')
->where('adre_id', $find_data['adre_id'])
->update(['adre_banlance'=>$adre_banlance]);
}
return '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
}
}
/**
* curl get
*
* @param string $url
* @param array $options
* @return mixed
*/
public static function curlGet($url = '', $options = array())
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
if (!empty($options)) {
curl_setopt_array($ch, $options);
}
//https请求 不验证证书和host
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public static function curlPost($url = '', $postData = '', $options = array())
{
if (is_array($postData)) {
$postData = http_build_query($postData);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置cURL允许执行的最长秒数
if (!empty($options)) {
curl_setopt_array($ch, $options);
}
//https请求 不验证证书和host
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public static function arrayToXml($arr)
{
$xml = "<xml>";
foreach ($arr as $key => $val) {
if (is_numeric($val)) {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
} else
$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
}
$xml .= "</xml>";
return $xml;
}
/**
* 获取签名
*/
public static function getSign($params, $key)
{
ksort($params, SORT_STRING);
$unSignParaString = self::formatQueryParaMap($params, false);
$signStr = strtoupper(md5($unSignParaString . "&key=" . $key));
return $signStr;
}
protected static function formatQueryParaMap($paraMap, $urlEncode = false)
{
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v) {
if (null != $v && "null" != $v) {
if ($urlEncode) {
$v = urlencode($v);
}
$buff .= $k . "=" . $v . "&";
}
}
$reqPar = '';
if (strlen($buff) > 0) {
$reqPar = substr($buff, 0, strlen($buff) - 1);
}
return $reqPar;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论