...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
use fast\Random;
|
|
|
|
|
|
/**
|
|
|
*
|
...
|
...
|
@@ -44,6 +45,9 @@ class Order extends Backend |
|
|
*/
|
|
|
public function index($ids = NULL)
|
|
|
{
|
|
|
if($ids){
|
|
|
$this->assign("user_id", $ids);
|
|
|
}
|
|
|
|
|
|
if($ids){
|
|
|
$this->assign("user_id", $ids);
|
...
|
...
|
@@ -95,4 +99,71 @@ class Order extends Backend |
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
public function add($ids = NULL)
|
|
|
{
|
|
|
|
|
|
if($ids){
|
|
|
$this->assign("user_id", $ids);
|
|
|
}
|
|
|
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
|
|
$params[$this->dataLimitField] = $this->auth->id;
|
|
|
}
|
|
|
|
|
|
$product = new \app\admin\model\Product();
|
|
|
$product = $product->where(['id'=>$params['product_id']])->find();
|
|
|
if(empty($product)){
|
|
|
$this->error($this->model->getError());
|
|
|
}
|
|
|
$product = $product->toArray();
|
|
|
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
|
|
|
$order_id = Random::uuid();
|
|
|
$order_id = str_replace("-","",$order_id);
|
|
|
|
|
|
$params['user_id'] = $ids;
|
|
|
$params['order_id'] = $order_id;
|
|
|
$params['status'] = 'success';
|
|
|
$params['product_doc'] = json_encode($product);;
|
|
|
$params['total'] = $product['price'];
|
|
|
$params['create_time'] = $now;
|
|
|
$params['third_order_id'] = '';
|
|
|
$params['count'] = $product['count'];
|
|
|
$params['remain'] = ($product['count'] == -1)?999999:$product['count'];
|
|
|
$params['start'] = $now;
|
|
|
$params['end'] = date('Y-m-d H:i:s',strtotime('+'.$product['dateCount'].' day',strtotime($now)));
|
|
|
$params['success_time'] = $now;
|
|
|
$params['notify'] = false;
|
|
|
|
|
|
try {
|
|
|
//是否采用模型验证
|
|
|
if ($this->modelValidate) {
|
|
|
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
$this->model->validate($validate);
|
|
|
}
|
|
|
$result = $this->model->allowField(true)->insert($params,false,true);
|
|
|
if ($result !== false) {
|
|
|
$this->success();
|
|
|
} else {
|
|
|
$this->error($this->model->getError());
|
|
|
}
|
|
|
} catch (\think\exception\PDOException $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (\think\Exception $e) {
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
} |
...
|
...
|
|