chore: 新增epay和cos插件相关类库及配置文件

- 新增epay v2、v3、v3new版本的支付类库及证书文件
- 新增cos云存储类库文件
- 调整文件上传保存格式为按分类存储
- 修复会员、规则、类目等语言翻译键名
- 新增小程序图标等静态资源文件
这个提交包含在:
YuanWen
2026-11-04 09:33:57 +08:00
父节点 361dffc7d8
当前提交 78d45eea74
共有 1176 个文件被更改,包括 102605 次插入 和 4357 次删除

查看文件

@@ -16,11 +16,12 @@ class Home extends Base
*/
public function index()
{
$cats = Db::name('service_cat')
$rawCats = Db::name('service_cat')
->field('id,name,icon')
->where('status', 'normal')
->order('weigh desc,id asc')
->select();
$cats = $this->formatCats($rawCats);
$hot = Db::name('service')
->field('id,cat_id,name,price_type,base_price,max_price,unit,image,sales')
@@ -52,11 +53,12 @@ class Home extends Base
*/
public function cats()
{
$cats = Db::name('service_cat')
$rawCats = Db::name('service_cat')
->field('id,name,icon')
->where('status', 'normal')
->order('weigh desc,id asc')
->select();
$cats = $this->formatCats($rawCats);
foreach ($cats as &$c) {
$icon = (string)$c['icon'];
@@ -477,6 +479,30 @@ class Home extends Base
return $ret;
}
/**
* 格式化类目列表(统一网络图片 URL)
*/
protected function formatCats($cats)
{
if (empty($cats)) return [];
foreach ($cats as &$c) {
$icon = (string)$c['icon'];
if ($icon !== '') {
if (strpos($icon, 'http') === 0) {
$c['icon_url'] = $icon;
} elseif (strpos($icon, '/') !== false || strpos($icon, '.') !== false) {
$c['icon_url'] = cdnurl($icon, true);
} else {
$c['icon_url'] = '';
}
} else {
$c['icon_url'] = '';
}
}
unset($c);
return $cats;
}
/**
* 单项格式化(价格文案统一由此输出)
*/

查看文件

@@ -200,6 +200,9 @@ class Master extends Base
: ($row['price_type'] === 'quote' ? '师傅报价'
: ($row['price_type'] === 'custom' ? '用户自主定价' : '按面积计价'));
$row['user_price'] = $row['price_type'] === 'custom' ? (float)$row['base_amount'] : 0;
if (!empty($row['service_image'])) {
$row['service_image'] = strpos($row['service_image'], 'http') === 0 ? $row['service_image'] : cdnurl($row['service_image'], true);
}
}
unset($row);
@@ -369,6 +372,93 @@ class Master extends Base
/**
* 我的订单(师傅视角)
*/
/**
* 师傅端:输入客户 6 位短信核销码完成工单验收结算
* @ApiMethod (POST)
*/
public function verifyCode()
{
$orderId = (int)$this->request->post('order_id');
$code = trim((string)$this->request->post('verify_code', ''));
if ($orderId <= 0 || $code === '') {
$this->error('请输入 6 位核销验证码');
}
$master = $this->requireMaster();
$order = Db::name('order')->where('id', $orderId)->find();
if (!$order) {
$this->error('订单不存在');
}
if ((int)$order['master_id'] !== (int)$master['id']) {
$this->error('无权操作该订单');
}
if ((int)$order['status'] !== OrderStatus::PENDING_VERIFY) {
$this->error('当前状态(' . OrderStatus::label($order['status']) . ')不可核销');
}
if ((string)$order['verify_code'] !== '' && (string)$order['verify_code'] !== $code) {
$this->error('核销验证码不正确,请核对后重新输入');
}
$masterId = (int)$master['id'];
$payAmount = (float)$order['pay_amount'];
$rate = 10.00;
$commission = round($payAmount * $rate / 100, 2);
$settleAmount = round($payAmount - $commission, 2);
Db::startTrans();
try {
$this->transit($order, OrderStatus::COMPLETED, '师傅已录入客户 6 位短信验证码,核销完工', [
'verify_time' => time(),
'settle_status' => 1,
'settle_amount' => $settleAmount,
], 'master', $masterId);
Db::name('settle')->insert([
'order_id' => $orderId,
'master_id' => $masterId,
'order_amount' => $payAmount,
'commission_rate' => $rate,
'commission' => $commission,
'settle_amount' => $settleAmount,
'status' => 'settled',
'settle_time' => time(),
'createtime' => time(),
]);
$masterInfo = Db::name('master')->where('id', $masterId)->lock(true)->find();
$newMoney = round((float)$masterInfo['money'] + $settleAmount, 2);
Db::name('master')->where('id', $masterId)->update([
'money' => $newMoney,
'order_count' => (int)$masterInfo['order_count'] + 1,
'updatetime' => time(),
]);
Db::name('wallet_log')->insert([
'user_type' => 'master',
'user_id' => $masterId,
'type' => 'settle',
'amount' => $settleAmount,
'balance' => $newMoney,
'order_id' => $orderId,
'remark' => '工单 ' . $order['order_no'] . ' 短信验证码核销入账',
'createtime' => time(),
]);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('核销失败:' . $e->getMessage());
}
$this->notify('user', (int)$order['user_id'], '订单已核销完成', '您的工单已由师傅现场核销完成,感谢您的支持!', 'order', $orderId);
$this->success('验收核销成功!工费已结算至您的钱包', [
'settle_amount' => $settleAmount,
'balance' => $newMoney
]);
}
public function orders()
{
$master = $this->requireMaster();
@@ -683,6 +773,46 @@ class Master extends Base
* 师傅端订单抢单详情
* @ApiMethod (GET)
*/
/**
* 师傅端:施工现场发起增项补差价申请
* @ApiMethod (POST)
*/
public function requestDiff()
{
$orderId = (int)$this->request->post('order_id');
$amount = round((float)$this->request->post('amount'), 2);
$remark = trim((string)$this->request->post('remark', '现场增项费用'));
$image = trim((string)$this->request->post('image', ''));
if ($orderId <= 0 || $amount <= 0) {
$this->error('请输入有效的补差价金额');
}
$master = $this->requireMaster();
$order = Db::name('order')->where('id', $orderId)->find();
if (!$order || (int)$order['master_id'] !== (int)$master['id']) {
$this->error('无权操作该订单');
}
$allowedStatus = [OrderStatus::ARRIVED, OrderStatus::WORKING];
if (!in_array((int)$order['status'], $allowedStatus, true)) {
$this->error('当前状态不可发起增项补差价');
}
Db::name('order')->where('id', $orderId)->update([
'diff_amount' => $amount,
'diff_status' => 1, // 1: 待客户支付
'diff_remark' => mb_substr($remark, 0, 255),
'diff_image' => $image,
'updatetime' => time(),
]);
$this->addLog($orderId, (int)$order['status'], '师傅发起施工现场增项补差价申请 ¥' . $amount . ',原因:' . $remark, 'master', (int)$master['id']);
$this->notify('user', (int)$order['user_id'], '师傅发起增项补差价申请', '工单 ' . $order['order_no'] . ' 师傅申请增项补差价 ¥' . $amount . ',请查看并在线支付', 'order', $orderId);
$this->success('已发起增项补差价申请,请提醒客户在线支付');
}
public function orderDetail()
{
$master = $this->requireMaster();

查看文件

@@ -471,6 +471,104 @@ class Merchant extends Base
/**
* 当前用户商家档案:主账号直接匹配,关联账号通过绑定关系匹配
*/
/**
* 商户端:Excel 或结构化数据一键批量解析下单
* @ApiMethod (POST)
*/
public function importBatch()
{
$merchant = $this->requireMerchant();
$items = $this->request->post('items/a', []);
if (empty($items)) {
$items = $this->request->post('orders/a', []);
}
if (empty($items) || !is_array($items)) {
$this->error('导入数据不能为空');
}
$globalServiceId = (int)$this->request->post('service_id', 1);
$svc = Db::name('service')->where('id', $globalServiceId)->find();
$defaultServiceName = $svc ? $svc['name'] : '家居安装';
$defaultPrice = $svc && (float)$svc['base_price'] > 0 ? (float)$svc['base_price'] : 80.00;
$ordersCreated = [];
$totalAmount = 0.00;
Db::startTrans();
try {
$batchNo = 'MB' . date('YmdHis') . mt_rand(1000, 9999);
foreach ($items as $idx => $item) {
$contact = trim((string)(isset($item['contact']) ? $item['contact'] : '买家'));
$mobile = trim((string)(isset($item['mobile']) ? $item['mobile'] : ''));
$address = trim((string)(isset($item['address']) ? $item['address'] : ''));
$serviceName = trim((string)(isset($item['service_name']) ? $item['service_name'] : $defaultServiceName));
$goodsModel = trim((string)(isset($item['goods_model']) ? $item['goods_model'] : ''));
$goodsNum = max(1, (int)(isset($item['goods_num']) ? $item['goods_num'] : (isset($item['num']) ? $item['num'] : 1)));
if (!$mobile || !$address) {
continue;
}
$orderNo = date('YmdHis') . mt_rand(100000, 999999);
$singlePrice = isset($item['price']) && (float)$item['price'] > 0 ? (float)$item['price'] : $defaultPrice;
$baseAmount = round($singlePrice * $goodsNum, 2);
$verifyCode = (string)mt_rand(100000, 999999);
$orderId = Db::name('order')->insertGetId([
'order_no' => $orderNo,
'user_id' => $this->uid(),
'service_id' => $globalServiceId,
'service_name' => $serviceName,
'goods_model' => $goodsModel,
'goods_num' => $goodsNum,
'contact' => $contact,
'mobile' => $mobile,
'address' => $address,
'province' => isset($item['province']) ? $item['province'] : '贵州省',
'city' => isset($item['city']) ? $item['city'] : '贵阳市',
'district' => isset($item['district']) ? $item['district'] : '南明区',
'floor' => isset($item['floor']) ? (int)$item['floor'] : 1,
'has_elevator' => isset($item['elevator']) ? (int)$item['elevator'] : 1,
'base_amount' => $baseAmount,
'total_amount' => $baseAmount,
'pay_amount' => $baseAmount,
'status' => OrderStatus::PENDING_ACCEPT,
'pay_status' => 1,
'pay_time' => time(),
'verify_code' => $verifyCode,
'createtime' => time(),
'updatetime' => time(),
]);
Db::name('merchant_order')->insert([
'merchant_id' => (int)$merchant['id'],
'order_id' => $orderId,
'batch_no' => $batchNo,
'createtime' => time(),
]);
$ordersCreated[] = [
'order_id' => $orderId,
'order_no' => $orderNo,
'contact' => $contact,
'amount' => $baseAmount
];
$totalAmount += $baseAmount;
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('批量导入失败:' . $e->getMessage());
}
$this->success('批量下单导入成功!', [
'batch_no' => $batchNo,
'count' => count($ordersCreated),
'total_amount' => round($totalAmount, 2),
'orders' => $ordersCreated,
]);
}
protected function merchantInfo()
{
$merchant = Db::name('merchant')->where('user_id', $this->uid())->find();

查看文件

@@ -24,6 +24,12 @@ class Order extends Base
*/
public function create()
{
// 频次防刷限制:同一用户 3 秒内禁止连续下单,防并发重复创单
$lastOrderTime = Db::name('order')->where('user_id', $this->uid())->order('id desc')->value('createtime');
if ($lastOrderTime && (time() - (int)$lastOrderTime) < 3) {
$this->error('操作过于频繁,请稍候再试');
}
$serviceId = (int)$this->request->post('service_id');
$addressId = (int)$this->request->post('address_id');
$appointTime = (int)$this->request->post('appoint_time', 0);
@@ -203,6 +209,22 @@ class Order extends Base
'custom' => '用户自主定价',
'range' => '按面积计价',
];
if (!empty($goodsList) && is_array($goodsList)) {
foreach ($goodsList as $g) {
Db::name('order_goods')->insert([
'order_id' => (int)$id,
'service_id' => isset($g['service_id']) ? (int)$g['service_id'] : (int)$serviceId,
'goods_name' => isset($g['goods_name']) ? (string)$g['goods_name'] : (string)$serviceName,
'goods_model' => isset($g['goods_model']) ? (string)$g['goods_model'] : (string)$goodsModel,
'goods_num' => isset($g['goods_num']) ? max(1, (int)$g['goods_num']) : 1,
'goods_image' => isset($g['goods_image']) ? (string)$g['goods_image'] : '',
'addon_services' => isset($g['addon_services']) ? (string)$g['addon_services'] : '',
'base_price' => isset($g['base_price']) ? (float)$g['base_price'] : (float)$amount['base_amount'],
'createtime' => time(),
]);
}
}
$this->addLog($id, OrderStatus::PENDING_PAY, '用户下单(' . (isset($modeText[$priceType]) ? $modeText[$priceType] : '一口价') . ')', 'user', $this->uid());
$this->success('下单成功', [
@@ -259,12 +281,63 @@ class Order extends Base
$this->error('支付失败:' . $e->getMessage());
}
// 订单广播通知:进入接单大厅后,通知周边在线师傅
if ($nextStatus === OrderStatus::PENDING_ACCEPT) {
try {
$masters = Db::name('master')->where('status', 'normal')->limit(20)->select();
foreach ($masters as $m) {
$this->notify('master', (int)$m['user_id'], '新工单就绪通知', '同城有新工单【' . $order['order_no'] . '】进入接单大厅,请尽快前往抢单!', 'order', $orderId);
}
} catch (\Exception $e) {}
}
$this->success('支付成功');
}
/**
* 我的订单列表
*/
/**
* 用户在线支付施工增项补差价
* @ApiMethod (POST)
*/
public function payDiff()
{
$orderId = (int)$this->request->post('order_id');
$order = $this->ownOrder($orderId, 'user');
if ((int)$order['diff_status'] !== 1 || (float)$order['diff_amount'] <= 0) {
$this->error('当前订单无待支付的增项补差价');
}
$diffAmount = (float)$order['diff_amount'];
$newPayAmount = round((float)$order['pay_amount'] + $diffAmount, 2);
Db::startTrans();
try {
Db::name('order')->where('id', $orderId)->update([
'diff_status' => 2,
'pay_amount' => $newPayAmount,
'updatetime' => time(),
]);
$this->addLog($orderId, (int)$order['status'], '用户在线支付施工增项补差价 ¥' . $diffAmount, 'user', $this->uid());
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('支付失败:' . $e->getMessage());
}
if ((int)$order['master_id'] > 0) {
$m = Db::name('master')->where('id', $order['master_id'])->find();
if ($m) {
$this->notify('master', (int)$m['user_id'], '客户已支付增项补差价', '工单 ' . $order['order_no'] . ' 客户已支付增项补差价 ¥' . $diffAmount, 'order', $orderId);
}
}
$this->success('增项补差价支付成功!', ['pay_amount' => $newPayAmount]);
}
public function index()
{
$status = $this->request->param('status', 'all');
@@ -378,6 +451,7 @@ class Order extends Base
$this->success('', [
'order' => $this->formatOrder($order),
'goods_list' => Db::name('order_goods')->where('order_id', $orderId)->select(),
'master' => $master,
'logs' => $logs,
'media' => $media,
@@ -631,6 +705,12 @@ class Order extends Base
'urgent' => (int)$row['urgent'],
'price_type_text' => $this->priceTypeText($row['price_type']),
'is_order_owner' => (int)$row['user_id'] === $this->uid(),
'diff_amount' => isset($row['diff_amount']) ? (float)$row['diff_amount'] : 0.00,
'diff_status' => isset($row['diff_status']) ? (int)$row['diff_status'] : 0,
'diff_remark' => isset($row['diff_remark']) ? (string)$row['diff_remark'] : '',
'diff_image' => isset($row['diff_image']) ? (string)$row['diff_image'] : '',
'empty_run_fee' => isset($row['empty_run_fee']) ? (float)$row['empty_run_fee'] : 0.00,
'auto_quote_timeout' => isset($row['auto_quote_timeout']) ? (int)$row['auto_quote_timeout'] : 0,
]);
}