1]; $list = Db::name('product')->field('content',true)->where($where)->order('weigh desc')->autopage()->select(); $list = list_domain_image($list,['images']); if(!empty($list)){ foreach($list as $key => &$item){ //第一个图 $item['image'] = isset($item['images'][0]) ? $item['images'][0] : ''; } } $this->success(1,$list); } public function info(){ $id = input('id',0); $info = Db::name('product')->where('is_show',1)->where('id',$id)->find(); if(!$info){ $this->error('不存在的商品'); } $info = info_domain_image($info,['images']); //第一个图 $info['image'] = isset($info['images'][0]) ? $info['images'][0] : ''; $this->success(1,$info); } //兑换 public function buy(){ $remark = input('remark',''); $product_id = input('id',0); $info = Db::name('product')->where('is_show',1)->where('id',$product_id)->find(); if(!$info){ $this->error('不存在的商品'); } Db::startTrans(); //下单 $data = [ 'order_no' => createUniqueNo('A',$this->auth->id), 'product_id' => $product_id, 'user_id' => $this->auth->id, 'createtime' => time(), 'pay_fee' => $info['price'], 'remark' => $remark, 'status' => 0, ]; $order_id = Db::name('order')->insertGetId($data); if(!$order_id){ Db::rollback(); $this->error('兑换失败'); } //扣钱 $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$info['price'],3,'积分兑换'.$info['title'],'order',$order_id); if($rs_wallet['status'] == false){ Db::rollback(); $this->error($rs_wallet['msg']); } Db::commit(); $this->success('兑换成功',$order_id); } }