|
@@ -132,69 +132,38 @@ class Power extends Controller
|
|
|
*/
|
|
|
public function send()
|
|
|
{
|
|
|
- if($this->request->post()){
|
|
|
- $data = $this->request->post();
|
|
|
- if (!isset($data['mid']) || $data['mid']==''){
|
|
|
- $this->error('请选择用户');
|
|
|
- }
|
|
|
- $inventory = Db::name($this->table)->where('id',$data['id'])->value('inventory');
|
|
|
- $info = Db::name($this->table)->where('id',$data['id'])->find();
|
|
|
-
|
|
|
- $redis = new Redis();
|
|
|
- $zhuzao_count = $redis->Llen('collectionHash_'.$data['id']);
|
|
|
- $com = true;
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $array = [];
|
|
|
- for ($i=0;$i<$data['number'];$i++){
|
|
|
- //获取排名
|
|
|
- $rank = getRanking($data['id'])+1;
|
|
|
- $tag = getTag($data['id'],$rank,$inventory);
|
|
|
- saveRanking($data['id']);
|
|
|
- $company = '梵易(广州)艺术有限公司';
|
|
|
- $hash = getCompanyHash($data['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_no'=>get_order_sn(),
|
|
|
- 'tag'=>$tag,
|
|
|
- 'mid'=>$data['mid'],
|
|
|
- 'c_id'=>$data['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'=>''
|
|
|
- ];
|
|
|
- $array[] = $date;
|
|
|
- }
|
|
|
- Db::name('store_order_info')->insertAll($array);
|
|
|
-
|
|
|
- Db::commit();
|
|
|
- } catch (\Exception $e){
|
|
|
- Db::rollback();
|
|
|
- $com = false;
|
|
|
- }
|
|
|
- if ($com){
|
|
|
- //减掉库存
|
|
|
- loseCollectionInventory($data['id'],$data['number']);
|
|
|
- $this->success('赠送成功');
|
|
|
- }else{
|
|
|
- $this->error('赠送失败');
|
|
|
- }
|
|
|
- }else{
|
|
|
+ if($this->request->isGet()) {
|
|
|
$id=$this->request->get('id');
|
|
|
$this->assign('id',$id);
|
|
|
$goods_list = Db::name('store_collection')->where(['is_deleted'=>0,'type'=>1])->order('id desc')->column('name','id');
|
|
|
$this->fetch('',['goods_list'=>$goods_list]);
|
|
|
}
|
|
|
+
|
|
|
+ if($this->request->post()){
|
|
|
+ $data = $this->request->post();
|
|
|
+ $goods_id = $this->request->post('send_goods');
|
|
|
+ $coll_id = $this->request->post('coll_id');
|
|
|
+ if(!$goods_id) $this->error('请选择藏品');
|
|
|
+ $coll_info = getCollectionInfoHash($goods_id);// 赠送的藏品信息
|
|
|
+ if ($coll_info['is_deleted']==1 || $coll_info['status']==0) $this->error('藏品已下架');
|
|
|
+ $inventory = getCollectionInventory($goods_id);
|
|
|
+ $where= [];
|
|
|
+ $where[] = ['c_id','=',$coll_id];
|
|
|
+ $where[] = ['resale_status','=',1];
|
|
|
+ $where[] = ['is_destruction','=',1];
|
|
|
+ $num = Db::name('store_order_info')->where($where)->count();// 需要赠送总数
|
|
|
+ if ($inventory < 1 || $inventory<$num) $this->error('库存不足');
|
|
|
+
|
|
|
+ //获取是否已经铸造hash
|
|
|
+ $hashCount = getLenCollection($goods_id);
|
|
|
+ if ((!$hashCount || $hashCount<$num) && $coll_info['type'] != 3) $this->error('hash未铸造,无法购买');
|
|
|
+ //先减掉库存
|
|
|
+ loseCollectionInventory($goods_id,$num);
|
|
|
+
|
|
|
+ Db::name('collection_power_send')->insert(['coll_id'=>$coll_id,'send_goods'=>$goods_id,'power_id'=>$data['id']]);
|
|
|
+
|
|
|
+ $this->success('设置成功,稍后赠送用户藏品');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|