travel/service/app/admin/controller/ProductsController.php

63 lines
2.1 KiB
PHP
Raw Normal View History

2024-10-12 19:16:04 +08:00
<?php
namespace app\admin\controller;
use app\model\Admins;
use app\model\Onlines;
use app\model\Orders;
use app\model\Products;
use support\Log;
use support\Request;
use support\Redis;
class ProductsController extends base {
/**
* 线路列表
* @param Request $request
* @return \support\Response
* @throws \think\db\exception\DbException
*/
public function list(Request $request) {
$query = Products::where('status', 1)->order('id', 'desc');
if($username = $request->get('username')) {
$query->where('username', $username);
}
if($status = $request->get('status')) {
$query->where('status', $status);
}
if($is_order = $request->get('is_order')) {
$query->where('is_order', $is_order);
}
$list = $query->paginate($request->get('limit',1000));
return $this->success($list,null,['oss' => array_values(array_map(function ($os, $k) {
return ['id' => $k, 'os' => $os];
}, Orders::OSS, array_keys(Orders::OSS)))]);
}
public function add(Request $request) {
if (!$request->post('os')) {
return $this->error(2001, '请选择平台.');
}
if (!$request->post('product_name')) {
return $this->error(2001, '线路名称必填');
}
if (!$request->post('third_product_id')) {
return $this->error(2001, '线路id必填');
}
$where = ['os' => $request->get('os'), 'third_product_id' => $request->get('third_product_id')];
$product = (new Products())->where($where)->find();
if (!empty($product)) {
return $this->error(2002, '线路已存在');
}
$product = new Products();
$product->os = $request->post('os');
$product->third_product_id = $request->post('third_product_id');
$product->product_name = $request->post('product_name');
$product->status = 1;
$product->save();
Log::info('product:' . json_encode($product));
return $this->success([]);
}
}