UserMater.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%user_mater}}".
  6. *
  7. * @property integer $id
  8. * @property integer $uid
  9. * @property string $backpic
  10. * @property string $company
  11. * @property string $type_id
  12. * @property string $name
  13. * @property integer $age
  14. * @property string $position
  15. * @property string $tel
  16. * @property string $qq
  17. * @property string $wechat
  18. * @property string $latitude
  19. * @property string $longitude
  20. * @property string $hashcode
  21. * @property string $province
  22. * @property string $city
  23. * @property string $area
  24. * @property string $address
  25. * @property string $intro
  26. * @property integer $c_time
  27. * @property integer $u_time
  28. * @property integer $member
  29. * @property integer $vip_start
  30. * @property integer $vip_end
  31. */
  32. class UserMater extends \yii\db\ActiveRecord
  33. {
  34. /**
  35. * @inheritdoc
  36. */
  37. const STATUS_YES = 10;
  38. const STATUS_NO = 0;
  39. const MEMBER_YES = 1;
  40. const MEMBER_NO = 0;
  41. public static function tableName()
  42. {
  43. return '{{%user_mater}}';
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [['c_time','u_time'], 'default','value'=>time()],
  52. //[['status'], 'default','value'=>self::STATUS_YES],
  53. //[['uid','company','type_id','name','tel'], 'required'],
  54. [['uid'], 'required'],
  55. [['company','name','backpic','position','tel','qq','wechat','latitude','longitude','hashcode','province','city','area','address','intro'], 'string'],
  56. [['c_time','type_id','uid','u_time','member','vip_start','vip_end'], 'integer'],
  57. ];
  58. }
  59. /**
  60. * @inheritdoc
  61. */
  62. public function attributeLabels()
  63. {
  64. return [
  65. 'id' => 'ID',
  66. 'uid' => '用户id',
  67. 'backpic' => '背景图片',
  68. 'company' => '企业名称',
  69. 'type_id' => '类型id',
  70. 'name' => '姓名',
  71. 'age' => '经营年限',
  72. 'position' => '职位',
  73. 'tel' => '手机号',
  74. 'qq' => 'qq',
  75. 'wechat' => '微信',
  76. 'latitude' => '纬度',
  77. 'longitude' => '经度',
  78. 'hashcode' => '经纬code',
  79. 'province' => '省编号',
  80. 'city' => '市编号',
  81. 'area' => '区编号',
  82. 'address' => '地址',
  83. 'intro' => '介绍',
  84. 'c_time' => '添加时间',
  85. 'u_time' => '更新时间',
  86. 'member' => '是否会员',
  87. 'vip_start' =>'会员开始时间',
  88. 'vip_end' =>'会员结束时间',
  89. ];
  90. }
  91. public function getType(){
  92. return $this->hasOne(MaterType::className(),['id'=>'type_id']);
  93. }
  94. public function getUser(){
  95. return $this->hasOne(User::className(),['id'=>'uid']);
  96. }
  97. /**
  98. * 商品展示图片
  99. * @return $this
  100. */
  101. public function getImages(){
  102. return $this->hasMany(ImageSource::className(),['topid'=>'uid'])->where(['type'=>ImageSource::TYPE_MATER_GOOD,'status'=>ImageSource::STATUS_YES]);
  103. }
  104. public function getAreaname()
  105. {
  106. $areaname ="";
  107. $provinceList = Yii::$app->cache->get('provinceList');
  108. if(!empty($provinceList))
  109. {
  110. if(!empty($this->province))
  111. $areaname .=empty($provinceList[$this->province]) ? "":$provinceList[$this->province] ;
  112. }else{
  113. $list = Area::find()->where(['type'=>1])->all();
  114. if(!empty($list))
  115. {
  116. foreach ($list as $value)
  117. {
  118. $provinceList[$value->area_id] = $value->area;
  119. if($this->province == $value->area_id)
  120. $areaname .= $value->area;
  121. }
  122. Yii::$app->cache->set('provinceList',$provinceList);
  123. }
  124. }
  125. $cityList = Yii::$app->cache->get('cityList');
  126. if(!empty($cityList))
  127. {
  128. if(!empty($this->city))
  129. $areaname .=empty($cityList[$this->city]) ? "":$cityList[$this->city];
  130. }else{
  131. $list = Area::find()->where(['type'=>2])->all();
  132. if(!empty($list))
  133. {
  134. foreach ($list as $value)
  135. {
  136. $cityList[$value->area_id] = $value->area;
  137. if($this->city == $value->area_id)
  138. $areaname .= $value->area;
  139. }
  140. Yii::$app->cache->set('cityList',$cityList);
  141. }
  142. }
  143. $areaList = Yii::$app->cache->get('areaList');
  144. if(!empty($areaList))
  145. {
  146. if(!empty($this->area))
  147. $areaname .=empty($areaList[$this->area])? "":$areaList[$this->area];
  148. }else{
  149. $list = Area::find()->where(['type'=>3])->all();
  150. if(!empty($list))
  151. {
  152. foreach ($list as $value)
  153. {
  154. $areaList[$value->area_id] = $value->area;
  155. if($this->area == $value->area_id)
  156. $areaname .= $value->area;
  157. }
  158. Yii::$app->cache->set('areaList',$areaList);
  159. }
  160. }
  161. return $areaname;
  162. }
  163. }