|
@@ -162,6 +162,7 @@ class User extends Backend
|
|
|
}
|
|
|
if (!empty($params['u_id'])) {
|
|
|
$userWhere['u_id'] = $params['u_id'];
|
|
|
+ $userWhere['id'] = ['neq',$ids];
|
|
|
$user = $this->model->where($userWhere)->find();
|
|
|
if (!empty($user)) {
|
|
|
throw new Exception('前端用户ID已存在');
|
|
@@ -314,4 +315,76 @@ class User extends Backend
|
|
|
]);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 钻石充值
|
|
|
+ * @param null $ids
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function addJewel($ids=null)
|
|
|
+ {
|
|
|
+ /* 判断数据是否存在*/
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ /* 判断是否有权限访问*/
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if (!$params) {
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
+ $row->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ if (!empty($params['jewel_add'])) {//钻石充值
|
|
|
+ $userWhere['id'] = $row['id'];
|
|
|
+ $user = Db::name('user')->where($userWhere)->lock(true)->find();
|
|
|
+ $before = isset($user['jewel']) ? $user['jewel'] : 0;
|
|
|
+ $jewelRes = model('Wallet')->lockChangeAccountRemain($row['id'],$params['jewel_add'],'+',$before,$remark='钻石充值()',17,'jewel');
|
|
|
+ if (!$jewelRes['status']) {
|
|
|
+ throw new Exception($jewelRes['msg']);
|
|
|
+ }
|
|
|
+ $params['jewel'] = bcadd($user['jewel'],$params['jewel_add']);
|
|
|
+ //充值日志记录
|
|
|
+ //判断是否首充
|
|
|
+ $jewellogWhere['user_id'] = $row['id'];
|
|
|
+ $jewellogWhere['type'] = 1;
|
|
|
+ $userJewelLog = model('UserJewelLog')->where($jewellogWhere)->find();
|
|
|
+ $isFirst = 1;
|
|
|
+ if (!empty($userJewelLog)) {
|
|
|
+ $isFirst = 0;
|
|
|
+ }
|
|
|
+ $preUserId = $user['pre_userid'];
|
|
|
+ $userRechargeLogRes = model('UserRechargeLog')->addRecord($row['id'], $params['jewel_add'], $user['money'], $params['jewel'], $user['money'], 4, 4,$isFirst,$preUserId);
|
|
|
+ if (!$userRechargeLogRes) {
|
|
|
+ throw new Exception('充值记录生成失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result = $row->allowField(true)->save($params);
|
|
|
+ if ($result == false) {
|
|
|
+ throw new Exception(__('No rows were updated'));
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ $this->success();
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->view->assign("row", $row);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
}
|