1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use yii\web\Response;
- use app\models\entity\Projecttypes;
- use app\models\entity\AccountsJobtypes;
- use app\models\entity\Accounts;
- /**
- * ContactForm is the model behind the contact form.
- */
- class UserModel extends Model
- {
- public $employeesArray = [];
- public $company_id = 3;
-
- public function getListUserToAdd() {
-
- $url = '62.141.88.61:8085/Thingworx/Things/2050RepairsLibrary/Services/users';
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","AppKey: 6a7bdbaa-6bc1-4159-a2f4-07a13c8907d1"));
- curl_setopt($curl, CURLOPT_TIMEOUT, 20);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonEncoded);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
-
- $result = curl_exec($curl);
- //$info = curl_getinfo($curl, CURLINFO_HEADER_OUT);
- $res = json_decode($result,true);
- $listEmployee = json_decode($res['rows'][0]["result"],true);
- $i = 0;
- $employeesArray = [];
- foreach($listEmployee['data'] as $employee){
- if( 2 == $i){
- break;
- }
- $employeesArray[] = $employee;
- //echo "<pre>";var_dump($employee); echo "</pre>";
- $i++;
- }
- curl_close($curl);
- $this->employeesArray = $employeesArray;
- return true;
- }
-
- public function createAccount() {
-
- foreach ($this->employeesArray as $user) {
-
- $accountsEntity = new Accounts();
- $accountsEntity->id = $user['id'];
- $accountsEntity->name = $user['name'];
- $accountsEntity->cmdlevel = 1;
- $accountsEntity->phone = '+7(916)9254713';
- $accountsEntity->password = md5('123');
- $accountsEntity->login = 'login'.rand(0,999);
- $accountsEntity->company_id = $this->company_id;
- if($accountsEntity->save()){
- $accountsJobtypesEntity = new AccountsJobtypes();
- $accountsJobtypesEntity->accounts_id = $accountsEntity->id;
- $accountsJobtypesEntity->jobtypes_id = 64;
- $accountsJobtypesEntity->save();
- } else {
- return false;
- }
- }
- return true;
-
- }
- }
|