Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

161 linhas
4.4 KiB

  1. <?php
  2. namespace backend\modules\zzcs\models;
  3. use Yii;
  4. use yii\db\Expression;
  5. /**
  6. * This is the model class for table "opera_hotel_work_order_user".
  7. *
  8. * @property integer $id
  9. * @property integer $cancel_flag
  10. * @property integer $create_user
  11. * @property string $create_time
  12. * @property string $type
  13. * @property integer $connect_user
  14. * @property integer $work_order_id
  15. */
  16. class OperaHotelWorkOrderUser extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return 'opera_hotel_work_order_user';
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['cancel_flag', 'create_user', 'connect_user', 'work_order_id'], 'integer'],
  32. [['create_user', 'create_time'], 'required'],
  33. [['cancel_flag', ], 'safe'],
  34. [['create_time', 'type'], 'string', 'max' => 255],
  35. ];
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'cancel_flag' => 'Cancel Flag',
  45. 'create_user' => 'Create User',
  46. 'create_time' => 'Create Time',
  47. 'type' => 'Type',
  48. 'connect_user' => 'Connect User',
  49. 'work_order_id' => 'Work Order ID',
  50. ];
  51. }
  52. /**
  53. * Function Description:获取该工单相关人员信息
  54. * Function Name: getUsersByWorkOrderId
  55. * @param $workOrderId
  56. *
  57. * @return mixed
  58. *
  59. * @author 冒炎
  60. */
  61. public function getUsersByWorkOrderId($workOrderId){
  62. $select = [
  63. 'a.type',
  64. 'a.connect_user',
  65. 'b.true_name',
  66. 'user_name'=>new Expression("ifnull(b.user_name,'未知')")
  67. ];
  68. $where = [
  69. 'and',
  70. ['=','a.cancel_flag',0],
  71. ['=','a.work_order_id',$workOrderId]
  72. ];
  73. $list = self::find()
  74. ->select($select)
  75. ->from(self::tableName() . ' a')
  76. ->leftJoin(BaseUser::tableName() . ' b' , 'a.connect_user = b.id')
  77. ->where($where)
  78. ->asArray()
  79. ->all();
  80. $accept_arr = [];
  81. $copy_arr = [];
  82. foreach($list as $v){
  83. if($v['type'] ==0 ){//处理人
  84. if(empty($v['true_name'])){
  85. $accept_arr[] = array('id'=>$v['connect_user'],'name'=>$v['user_name']);
  86. }else{
  87. $accept_arr[] = array('id'=>$v['connect_user'],'name'=>$v['true_name']);
  88. }
  89. }else{//抄送人
  90. if(empty($v['true_name'])){
  91. $copy_arr[] = array('id'=>$v['connect_user'],'name'=>$v['user_name']);
  92. }else{
  93. $copy_arr[] = array('id'=>$v['connect_user'],'name'=>$v['true_name']);
  94. }
  95. }
  96. }
  97. $arr ['accept'] = $accept_arr;
  98. $arr ['copy'] = $copy_arr;
  99. return $arr;
  100. }
  101. /**
  102. * Function Description:新增数据
  103. * Function Name: addWorkUser
  104. * @param $type
  105. * @param $connect_user
  106. * @param $work_id
  107. * @return bool
  108. * @author 田玲菲
  109. */
  110. public function addWorkUser($type,$connect_user,$work_id){
  111. try{
  112. $date = date('Y-m-d H:i:s', time());
  113. $uid = Yii::$app->request->cookies->getValue('user_id', 0);
  114. $this->cancel_flag = 0;
  115. $this->create_time = $date;
  116. $this->create_user = $uid;
  117. $this->type = $type;
  118. $this->connect_user = intval($connect_user);
  119. $this->work_order_id = intval($work_id);
  120. return $this->save();
  121. }catch(\Exception $exception){
  122. return false;
  123. }
  124. }
  125. /**
  126. * Function Description:
  127. * Function Name: addCommentUser
  128. * @param $id
  129. * @param $time
  130. * @param $user_id
  131. * @param $user_arr
  132. *
  133. * @return int
  134. * @throws \yii\db\Exception
  135. *
  136. * @author 冒炎
  137. */
  138. public function addCommentUser($id,$time,$user_id,$user_arr){
  139. $sql ='';
  140. foreach ($user_arr as $value){
  141. $sql .= "INSERT INTO opera_hotel_work_order_user
  142. (`create_user`,`create_time`,`type`,`connect_user`,`work_order_id`)
  143. VALUES({$user_id},'{$time}','{$value['type']}',TRIM({$value['id']}),{$id});";
  144. }
  145. $res = Yii::$app->db->createCommand($sql)->execute();
  146. return $res;
  147. }
  148. }