Browse Source

Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop

develop
lemon 5 years ago
parent
commit
38a32caddf
  1. 12
      MySQL_change.sql
  2. 5
      app/AdminAgent/Controllers/CategoryController.php
  3. 2
      app/AdminAgent/Controllers/OrderController.php
  4. 10
      app/AdminAgent/Forms/Setting.php
  5. 18
      app/Http/Controllers/Api/OrderController.php
  6. 2
      app/Http/Controllers/Api/TestController.php
  7. 5
      app/Models/AgentSetting.php
  8. 4
      resources/lang/zh_CN/setting.php

12
MySQL_change.sql

@ -213,7 +213,11 @@ ALTER TABLE `articles`
# 9:28 2021/8/30
ALTER TABLE `agent_products`
ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `content`,
ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`,
ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `earnest_timeout`,
ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`;
ADD COLUMN `deposit` DECIMAL(20,2) NOT NULL DEFAULT 0 COMMENT '订金' AFTER `content`,
ADD COLUMN `deposit_timeout` INT NOT NULL DEFAULT 0 COMMENT '订金支付超时时间,单位:分钟' AFTER `deposit`,
ADD COLUMN `earnest` DECIMAL(20,2) NOT NULL DEFAULT '0' COMMENT '定金' AFTER `deposit_timeout`,
ADD COLUMN `earnest_timeout` INT NOT NULL DEFAULT 0 COMMENT '定金支付超时时间,单位:分钟' AFTER `earnest`;
# 10:58 2021/8/30
ALTER TABLE `orders`
ADD COLUMN `timeout` TIMESTAMP NULL DEFAULT NULL COMMENT '订单超时时间,超过这个时间,订单将变为“已取消”' AFTER `verify_code`;

5
app/AdminAgent/Controllers/CategoryController.php

@ -100,8 +100,11 @@ class CategoryController extends AdminController
//不允许编辑的字段
$form->ignore(['id', 'deleted_at']);
$form->hidden(['agent_id']);
$form->agent_id = Admin::user()->id;
$form->sort = $form->sort ?? 255;
if (array_key_exists('sort', $form->input())) {
$form->sort = $form->sort ?? 255;
}
})->deleting(function (Form $form) {
//不允许修改非自己的数据
if (array_filter($form->model()->toArray(), fn($v) => $v['agent_id'] != Admin::user()->id)) {

2
app/AdminAgent/Controllers/OrderController.php

@ -52,6 +52,7 @@ class OrderController extends AdminController
$grid->column('status')
->using(OrderStatus::array())
->if(fn() => in_array($this->status, [OrderStatus::REFUNDING, OrderStatus::REFUNDED, OrderStatus::REFUSED_REFUND]))
->display('<a style="cursor: pointer;" class="btn btn-sm btn-info" href="javascript:;">退款详情</a>&nbsp;')
->modal('查看退款详情', function (Grid\Displayers\Modal $modal) {
$modal->icon('');
if (!$this->refund_info) {
@ -74,7 +75,6 @@ class OrderController extends AdminController
];
return Table::make($refund_info);
})
->display('<a style="cursor: pointer;" class="btn btn-sm btn-info" href="javascript:;">退款详情</a>&nbsp;') //放在modal下面可以去掉空格
->then(function (Grid\Column $column) {
if ($this->status == OrderStatus::REFUNDING) {
$column->append((new AuditRefund(null, 1))->setKey($this->id))->append('&nbsp;');

10
app/AdminAgent/Forms/Setting.php

@ -21,7 +21,7 @@ class Setting extends Form
AgentSetting::updateOrCreate(
['agent_id' => Admin::user()->id],
['setting' => json_encode($input), 'agent_id' => Admin::user()->id],
['setting' => $input, 'agent_id' => Admin::user()->id],
);
return $this->response()->success('保存成功')->refresh();
@ -32,8 +32,10 @@ class Setting extends Form
*/
public function form()
{
$this->text('earnest')->required()->help('用户支付订金、定金、首付款的金额');
$this->text('earnest_timeout')->required()->help('单位:分钟。当通过订金、定金、首付款支付时,用户超过该时间未支付将关闭订单,且定金不退');
$this->text('order_timeout')->required()->default(1440)
->help('订单超时时间,单位:分钟。(订金、定金支付的超时时间将根据产品设定的超时时间)');
$this->radio('auto_shelves')->options(['否', '是'])->required()->default(1)
->help('是否自动上架合作供应商的产品,如果选是,当合作供应商发布新产品之后,将自动上架供应商的产品');
}
/**
@ -44,6 +46,6 @@ class Setting extends Form
public function default()
{
$setting = AgentSetting::where('agent_id', Admin::user()->id)->value('setting');
return is_string($setting) ? json_decode($setting, true) : [];
return $setting ?? [];
}
}

18
app/Http/Controllers/Api/OrderController.php

@ -6,8 +6,8 @@ use App\Common\PayType;
use App\Http\Controllers\Controller;
use App\Models\Agent;
use App\Models\AgentProduct;
use App\Models\AgentSetting;
use App\Models\Coupon;
use App\Models\Product;
use App\Models\User;
use App\Models\Order;
use EasyWeChat\Factory;
@ -74,8 +74,8 @@ class OrderController extends Controller
}, $v['pictures']);
}
//10分钟内未付款订单提示付款
if ($v['status'] == Status::UNPAID) {
//10分钟内未付款订单提示付款 TODO 此部分由定时
/*if ($v['status'] == Status::UNPAID) {
$minute = $time - strtotime($v['created_at']);
//订单创建后10分钟内未付款则提示,否则取消订单
if ($minute < 600) {
@ -87,7 +87,7 @@ class OrderController extends Controller
//TODO 加回库存,未考虑到几天/几个月后再打开订单列表页的情况,需要定时任务处理
Product::query()->find($v['product_id'])->increment('stock', $v['num']);
}
}
}*/
}
//超时订单设置为已取消 TODO 测试阶段暂时注释
@ -154,6 +154,15 @@ class OrderController extends Controller
//代理商产品表减库存
$ap->decrement('stock', $formData['num']);
if ($formData['pay_type'] == PayType::DEPOSIT_PAY && $ap->deposit_timeout > 0) {
$timeout = date('Y-m-d H:i:s', time() + $ap->deposit_timeout * 60);
} else if ($formData['pay_type'] == PayType::EARNEST_PAY && $ap->earnest_timeout > 0) {
$timeout = date('Y-m-d H:i:s', time() + $ap->earnest_timeout * 60);
} else {
$order_timeout = AgentSetting::val($this->agent_id, 'order_timeout') ?? 1440;
$timeout = date('Y-m-d H:i:s', time() + $ap->earnest_timeout * $order_timeout);
}
// 存入订单表
$order = Order::query()->create([
'user_id' => $this->user_id,
@ -172,6 +181,7 @@ class OrderController extends Controller
'pay_type' => $formData['pay_type'],
'coupon_id' => join(',', $coupon_ids),
'guide_id' => $ap->guide_id,
'timeout' => $timeout,
]);
DB::commit();

2
app/Http/Controllers/Api/TestController.php

@ -16,6 +16,6 @@ class TestController
public function index()
{
//test
return AgentSetting::val(1, 'earnest') ?? 198.88;
return AgentSetting::val(11, 'order_timeout') ?? 188;
}
}

5
app/Models/AgentSetting.php

@ -9,6 +9,7 @@ class AgentSetting extends BaseModel
use HasFactory;
protected $fillable = ['agent_id', 'setting'];
protected $casts = ['setting' => 'json'];
public function __construct(array $attributes = [])
{
@ -16,9 +17,9 @@ class AgentSetting extends BaseModel
$this->timestamps = false;
}
public function scopeVal($query, $agent_id, $key)
public static function val($agent_id, $key)
{
$setting = json_decode($query->where('agent_id', $agent_id)->value('setting'), true);
$setting = static::query()->where('agent_id', $agent_id)->value('setting');
return $setting[$key] ?? null;
}
}

4
resources/lang/zh_CN/setting.php

@ -5,8 +5,8 @@ return [
'setting' => '系统设置',
],
'fields' => [
'earnest' => '定金金额',
'earnest_timeout' => '定金支付超时时间',
'order_timeout' => '订单超时时间',
'auto_shelves' => '自动上架',
],
'options' => [
],

Loading…
Cancel
Save