where('is_deleted',0) ->where('status',1) ->where('type',2) ->field('id,cover,name,label,price,inventory,now_inventory,sy_state,sell_time,end_time') ->order('sy_state asc,sell_time asc') ->select(); foreach ($list as &$v) { $v['now_inventory'] = getCollectionInventory($v['id']); } $this->success('成功',$list); } /** * @title 藏品详情 * @desc 藏品详情 * @author Gavin * @url /api/Synthetic/CollectionDetail * @method POST * @header name:Authorization require:1 desc:Token * * @param name:id type:string require:1 default:-- desc:藏品ID * * @return name:name type:string default:-- desc:藏品名称 * @return name:cover type:string default:-- desc:藏品图 * @return name:label type:string default:-- desc:标签 * @return name:price type:DECIMAL default:-- desc:价格 * @return name:inventory type:int default:-- desc:库存 * @return name:now_inventory type:int default:-- desc:剩余库存 * @return name:sy_state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已结束4:已售罄) * @return name:sell_time type:string default:-- desc:发行时间 * @return name:end_time type:string default:-- desc:结束时间 * @return name:describe type:string default:-- desc:商品描述 * @return name:instructions type:int default:1 desc:权益说明 * @return name:buy_notice type:int default:1 desc:购买须知 * @return name:warm_prompt type:int default:1 desc:温馨提示 * @return name:auth_img type:int default:1 desc:作者头像 * @return name:auth_name type:int default:1 desc:作者姓名 * @return name:is_exchange type:int default:1 desc:材料是否够(1:够,可以合成0:不够) * @return name:material@name type:string default:-- desc:材料名称 * @return name:material@cover type:string default:-- desc:材料图片 * @return name:material@num type:string default:-- desc:所需数量 * @return name:material@now_num type:string default:-- desc:当前所有数量 */ public function CollectionDetail(){ $collect_id = input('id'); if (!$collect_id) $this->error('参数错误'); checkSynCollectionState($collect_id); $info = Db::name('store_collection') ->where('is_deleted',0) ->where('status',1) ->where('type',2) ->where('id',$collect_id) ->field('id,cover,name,label,price,inventory,now_inventory,sy_state,sell_time,end_time,describe,buy_count,instructions,buy_notice,warm_prompt,auth_img,auth_name,share_img,intro') ->find(); if (!$info) $this->error('藏品不存在'); $info['describe'] = explode('|',$info['describe']); $info['now_inventory'] = getCollectionInventory($info['id']); $material = Db::name('store_collection_material') ->alias('a') ->join('store_collection b','a.c_id=b.id') ->where('a.cid',$collect_id) ->field('a.id,a.c_id,a.num,b.name,b.cover') ->select(); $info['is_exchange'] = $this->check_exchange($collect_id,$this->uid); foreach ($material as &$v){ $v['now_num'] = Db::name('store_order_info') ->where('c_id',$v['c_id']) ->where('mid',$this->uid) ->where('status','neq',2) ->where('is_destruction',1) ->count(); } $info['material'] = $material; $this->success('成功',$info); } /** * 判断材料是否足够可以兑换 */ public function check_exchange($id,$mid){ $list = Db::name('store_collection_material') ->alias('a') ->join('store_collection b','a.c_id=b.id') ->where('a.cid',$id) ->field('a.id,a.c_id,a.num,b.name,b.cover') ->select(); $is_exchange = 1; foreach ($list as &$v){ $user_count = Db::name('store_order_info') ->where('c_id',$v['c_id']) ->where('mid',$mid) ->where('status','neq',2) ->where('is_destruction',1) ->count(); if ($user_count<$v['num']){ $is_exchange = 0; break; } } return $is_exchange; } /** * @title 合成藏品 * @desc 合成藏品 * @author Gavin * @url /api/Synthetic/synCollection * @method POST * @header name:Authorization require:1 desc:Token * * @param name:id type:int require:1 default:1 desc:藏品ID */ public function synCollection(){ $id = input('id'); if (!$id) $this->error('参数错误'); $info = Db::name('store_collection') ->where('is_deleted',0) ->where('status',1) ->where('type',2) ->where('id',$id) ->find(); if (!$info) $this->error('藏品不存在'); $now_inventory = getCollectionInventory($id); if ($now_inventory<=0) $this->error('已售罄'); if (strtotime($info['sell_time'])>time()) $this->error('未开始,无法合成'); if (strtotime($info['end_time'])error('已结束,无法合成'); //$check_info = Db::name('store_order_info')->where('mid',$this->uid)->where('c_id',$id)->count(); // if ($check_info) $this->error('已合成过,只能合成一次'); //获取是否已经铸造hash $hashCount = getLenCollection($id); if (!$hashCount) $this->error('hash未铸造,无法合成'); $is_exchange = $this->check_exchange($id,$this->uid); if (!$is_exchange) $this->error('材料不足,无法合成'); $com = true; Db::startTrans(); try { $material = Db::name('store_collection_material') ->where('cid',$id) ->select(); foreach ($material as &$v){ Db::name('store_order_info') ->where('c_id',$v['c_id']) ->where('mid',$this->uid) ->where('status','neq',2) ->where('is_destruction',1) ->limit($v['num']) ->order('id asc') ->update(['is_destruction'=>0]); } //获取排名 $rank = getRanking($id); $tag = getTag($id,$rank,$info['inventory']); saveRanking($id); $company = '象链数藏'; $hash = getCompanyHash($id); $company_hash = $hash['hash']; $company_hash_time = $hash['create_at']; $tokenid = $hash['tokenid']; Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]); $collectors_hash = ''; $date = [ 'order_id'=>0, 'order_no'=>get_order_sn(), 'tag'=>$tag, 'mid'=>$this->uid, 'c_id'=>$id, 'name'=>$info['name'], 'cover'=>$info['cover'], 'pro_info'=>json_encode($info,true), 'company'=>$company, 'company_hash'=>$company_hash, 'company_hash_time'=>$company_hash_time, 'ddcid'=>$tokenid, 'collectors_hash'=>$collectors_hash, //'collectors_hash_time'=>'', 'status'=>5 ]; Db::name('store_order_info')->insert($date); Db::commit(); }catch (\Exception $e){ $com=false; Db::rollback(); $this->error($e->getMessage()); } if ($com){ setMemberInfoHash($this->uid); //减掉库存 loseCollectionInventory($id,1); $this->success('合成成功'); } $this->error('合成失败,请稍后重试'); } }