__('Status 1'),'0' => __('Status 0'),'2' => __('Status 2')]; } /** * 创建分享码 * @param $count 数量 * @param $lenght 长度 * @return void */ public function createCode($count,$lenght = 10){ $data = []; for($i=0;$i<$count;$i++){ $data[] = \fast\Random::alnum($lenght); } return $data; } /** * 绑定分享码 * @param $batchId * @param $count * @return void */ public function build($batchId,$count){ $codeList = $this->createCode($count); $data = []; foreach ($codeList as $code){ $data[] = [ 'uniacid'=>UNIACID, 'batch_id'=>$batchId, 'code'=>$code, 'status'=>1, 'createtime'=>time() ]; } self::insertAll($data); } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function batch() { return $this->belongsTo('Batch', 'batch_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function user() { return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } }