|
@@ -241,4 +241,89 @@ class Relation extends Api
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ ///////////////////////////关系卡///////////////////////
|
|
|
+
|
|
|
+ //关系卡列表
|
|
|
+ public function product_list(){
|
|
|
+ $list = Db::name('decorate_relation')->select();
|
|
|
+ $list = list_domain_image($list,['base_image']);
|
|
|
+
|
|
|
+ $relation = Db::name('relation')->where('is_show',1)->order('weigh desc')->column('name');
|
|
|
+ $relation = implode(',',$relation);
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ 'list' => $list,
|
|
|
+ 'relation' => $relation
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->success(1,$result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 购买并加入我的背包
|
|
|
+ */
|
|
|
+ public function buy_one() {
|
|
|
+ $number = input_post('number',1); //数量
|
|
|
+ $did = input_post('did',''); //装扮ID
|
|
|
+ if (!$did) {
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+ // 判断用户金币余额是否充足
|
|
|
+ $walletinfo = model('wallet')->getWallet($this->auth->id);
|
|
|
+
|
|
|
+ // 获取购买装扮需要的价格
|
|
|
+ $decorate = Db::name('decorate_relation')->where(['id'=>$did])->find();
|
|
|
+ if(!$decorate) {
|
|
|
+ $this->error("道具信息获取失败!");
|
|
|
+ }
|
|
|
+ if($walletinfo['gold'] < $decorate['price']) {
|
|
|
+ $this->error("您的金币不足,请先充值!");
|
|
|
+ }
|
|
|
+ // 进行购买逻辑
|
|
|
+ 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,
|
|
|
+ '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('购买失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //扣钱
|
|
|
+ $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$decorate['price'],31,'购买关系卡','user_decorate_relation',$log_id);
|
|
|
+ if($rs['status'] === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs['msg']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success("购买成功!");
|
|
|
+ }
|
|
|
}
|