Commit 9d062fa7 by 冷斌

update

parent 75dfde4d
......@@ -90,6 +90,7 @@ class Api_User extends PhalApi_Api {
'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
'id' => array('name' => 'id', 'type' => 'string', 'require' => true, 'desc' => 'id'),
'source' => array('name' => 'source', 'type' => 'int', 'require' => true, 'desc' => '类型,1主播,2邀请,3家族'),
),
'setCash' => array(
......@@ -920,7 +921,7 @@ class Api_User extends PhalApi_Api {
}
$domain = new Domain_User();
$info = $domain->rechange($this->uid, $this->id);
$info = $domain->rechange($this->uid, $this->id, $this->source);
if($info === 1){
$rs['code']=1001;
......@@ -930,7 +931,7 @@ class Api_User extends PhalApi_Api {
if($info === 2){
$rs['code']=1002;
$rs['msg']='积分不足';
$rs['msg']='魅力值不足';
return $rs;
}
......
......@@ -92,11 +92,11 @@ class Domain_User {
return $rs;
}
public function rechange($uid, $id) {
public function rechange($uid, $id, $source) {
$rs = array();
$model = new Model_User();
$rs = $model->rechange($uid, $id);
$rs = $model->rechange($uid, $id, $source);
return $rs;
}
......
......@@ -337,26 +337,60 @@ class Model_User extends PhalApi_Model_NotORM
];
}
public function rechange($uid, $id)
public function rechange($uid, $id, $source)
{
$rechange = DI()->notorm->recharge_rules->where('id=?', $id)->fetchOne();
if (empty($rechange)) {
return 1;
}
$cashvotes = $rechange['money'];
$user = DI()->notorm->users->select('votes')->where('id=?', $uid)->fetchOne();
if ($rechange['money'] > $user['votes']) {
if ($source == 1 && $cashvotes > $user['votes']) {
return 2;
}
if ($source == 2 && $cashvotes > $user['i_votes']) {
return 2;
}
if ($source == 3 && $cashvotes > $user['f_votes']) {
return 2;
}
$total = $rechange['money'] + $rechange['give'];
DI()->notorm->users->where('id = ?', $uid)->update([
'coin' => new NotORM_Literal("coin + {$total}"),
'votes' => new NotORM_Literal("votes - {$rechange['money']}"),
]);
$ifok = 0;
return 0;
if ($source == 1) {
$ifok = DI()->notorm->users->where('id = ? and votes>=?', $uid, $cashvotes)->update([
'coin' => new NotORM_Literal("coin + {$total}"),
'votes' => new NotORM_Literal("votes - {$cashvotes}")
]);
}
if ($source == 2) {
$ifok = DI()->notorm->users->where('id = ? and i_votes>=?', $uid, $cashvotes)->update([
'coin' => new NotORM_Literal("coin + {$total}"),
'i_votes' => new NotORM_Literal("i_votes - {$cashvotes}")
]);
}
if ($source == 3) {
$ifok = DI()->notorm->users->where('id = ? and f_votes>=?', $uid, $cashvotes)->update([
'coin' => new NotORM_Literal("coin + {$total}"),
'f_votes' => new NotORM_Literal("f_votes - {$cashvotes}")
]);
}
// DI()->notorm->users->where('id = ?', $uid)->update([
// 'coin' => new NotORM_Literal("coin + {$total}"),
// 'votes' => new NotORM_Literal("votes - {$rechange['money']}"),
// ]);
return !$ifok ? 2 : 0;
}
/* 关注 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment