|
- <?php
-
- namespace backend\modules\zzcs\models;
-
- use Yii;
- use yii\db\Expression;
-
- /**
- * This is the model class for table "opera_hotel_work_order_user".
- *
- * @property integer $id
- * @property integer $cancel_flag
- * @property integer $create_user
- * @property string $create_time
- * @property string $type
- * @property integer $connect_user
- * @property integer $work_order_id
- */
- class OperaHotelWorkOrderUser extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_hotel_work_order_user';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['cancel_flag', 'create_user', 'connect_user', 'work_order_id'], 'integer'],
- [['create_user', 'create_time'], 'required'],
- [['cancel_flag', ], 'safe'],
- [['create_time', 'type'], 'string', 'max' => 255],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'cancel_flag' => 'Cancel Flag',
- 'create_user' => 'Create User',
- 'create_time' => 'Create Time',
- 'type' => 'Type',
- 'connect_user' => 'Connect User',
- 'work_order_id' => 'Work Order ID',
- ];
- }
-
- /**
- * Function Description:获取该工单相关人员信息
- * Function Name: getUsersByWorkOrderId
- * @param $workOrderId
- *
- * @return mixed
- *
- * @author 冒炎
- */
- public function getUsersByWorkOrderId($workOrderId){
- $select = [
- 'a.type',
- 'a.connect_user',
- 'b.true_name',
- 'user_name'=>new Expression("ifnull(b.user_name,'未知')")
- ];
- $where = [
- 'and',
- ['=','a.cancel_flag',0],
- ['=','a.work_order_id',$workOrderId]
- ];
- $list = self::find()
- ->select($select)
- ->from(self::tableName() . ' a')
- ->leftJoin(BaseUser::tableName() . ' b' , 'a.connect_user = b.id')
- ->where($where)
- ->asArray()
- ->all();
- $accept_arr = [];
- $copy_arr = [];
- foreach($list as $v){
- if($v['type'] ==0 ){//处理人
- if(empty($v['true_name'])){
- $accept_arr[] = array('id'=>$v['connect_user'],'name'=>$v['user_name']);
- }else{
- $accept_arr[] = array('id'=>$v['connect_user'],'name'=>$v['true_name']);
- }
- }else{//抄送人
- if(empty($v['true_name'])){
- $copy_arr[] = array('id'=>$v['connect_user'],'name'=>$v['user_name']);
- }else{
- $copy_arr[] = array('id'=>$v['connect_user'],'name'=>$v['true_name']);
- }
- }
- }
- $arr ['accept'] = $accept_arr;
- $arr ['copy'] = $copy_arr;
- return $arr;
-
- }
-
-
- /**
- * Function Description:新增数据
- * Function Name: addWorkUser
- * @param $type
- * @param $connect_user
- * @param $work_id
- * @return bool
- * @author 田玲菲
- */
- public function addWorkUser($type,$connect_user,$work_id){
- try{
- $date = date('Y-m-d H:i:s', time());
- $uid = Yii::$app->request->cookies->getValue('user_id', 0);
- $this->cancel_flag = 0;
- $this->create_time = $date;
- $this->create_user = $uid;
- $this->type = $type;
- $this->connect_user = intval($connect_user);
- $this->work_order_id = intval($work_id);
- return $this->save();
- }catch(\Exception $exception){
- return false;
- }
- }
-
- /**
- * Function Description:
- * Function Name: addCommentUser
- * @param $id
- * @param $time
- * @param $user_id
- * @param $user_arr
- *
- * @return int
- * @throws \yii\db\Exception
- *
- * @author 冒炎
- */
- public function addCommentUser($id,$time,$user_id,$user_arr){
- $sql ='';
- foreach ($user_arr as $value){
- $sql .= "INSERT INTO opera_hotel_work_order_user
- (`create_user`,`create_time`,`type`,`connect_user`,`work_order_id`)
- VALUES({$user_id},'{$time}','{$value['type']}',TRIM({$value['id']}),{$id});";
- }
-
- $res = Yii::$app->db->createCommand($sql)->execute();
- return $res;
-
- }
- }
|