|
@@ -265,7 +265,11 @@ class Relation extends Api
|
|
|
* 购买并加入我的背包
|
|
|
*/
|
|
|
public function buy_one() {
|
|
|
- $number = input_post('number',1); //数量
|
|
|
+ $number = input_post('number',1,'intval'); //数量
|
|
|
+ if(!$number){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
$did = input_post('did',''); //装扮ID
|
|
|
if (!$did) {
|
|
|
$this->error();
|
|
@@ -285,38 +289,24 @@ class Relation extends Api
|
|
|
Db::startTrans();
|
|
|
|
|
|
// 添加到背包
|
|
|
- $map = [
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
- 'decorate_id' => $decorate['id'],
|
|
|
- ];
|
|
|
-
|
|
|
- $find = Db::name('user_decorate_relation')->where($map)->lock(true)->find();
|
|
|
-
|
|
|
- if($find){
|
|
|
- $update = [
|
|
|
- 'number' => $find['number'] + $number,
|
|
|
+ for($i=1;$i<=$number;$i++){
|
|
|
+ $data[] = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'decorate_id' => $decorate['id'],
|
|
|
+ 'is_using' => 0,
|
|
|
+ 'createtime' => time(),
|
|
|
'updatetime' => time(),
|
|
|
];
|
|
|
+ }
|
|
|
|
|
|
- $update_rs = Db::name('user_decorate_relation')->where($map)->update($update);
|
|
|
- if($update_rs === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error('购买失败');
|
|
|
- }
|
|
|
- $log_id = $find['id'];
|
|
|
- }else{
|
|
|
- $map['number'] = 1;
|
|
|
- $map['createtime'] = time();
|
|
|
- $map['updatetime'] = time();
|
|
|
- $log_id = Db::name('user_decorate_relation')->insertGetId($map);
|
|
|
- if(!$log_id){
|
|
|
- Db::rollback();
|
|
|
- $this->error('购买失败');
|
|
|
- }
|
|
|
+ $log_id = Db::name('user_decorate_relation')->insertAll($data);
|
|
|
+ if(!$log_id){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('购买失败');
|
|
|
}
|
|
|
|
|
|
//扣钱
|
|
|
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$decorate['price'],31,'购买关系卡','user_decorate_relation',$log_id);
|
|
|
+ $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$decorate['price'],31,'购买关系卡','user_decorate_relation',0);
|
|
|
if($rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
$this->error($rs['msg']);
|
|
@@ -335,13 +325,14 @@ class Relation extends Api
|
|
|
|
|
|
$map = [
|
|
|
'a.user_id' => $uid,
|
|
|
+ 'a.is_using'=> 0,
|
|
|
];
|
|
|
|
|
|
$list = Db::name('user_decorate_relation')
|
|
|
->alias('a')
|
|
|
- ->field('a.id,a.number,b.name,b.base_image')
|
|
|
- ->join('decorate b', 'a.decorate_id = b.id')
|
|
|
- ->where($map)->order('a.id desc')->autopage()->select();
|
|
|
+ ->field('a.id,a.decorate_id,b.name,b.base_image,count(a.decorate_id) as number')
|
|
|
+ ->join('decorate_relation b', 'a.decorate_id = b.id','LEFT')
|
|
|
+ ->where($map)->group('a.decorate_id')->order('a.id desc')->autopage()->select();
|
|
|
|
|
|
$list = list_domain_image($list,['base_image']);
|
|
|
|