2021-07-08 22:28:51 +08:00
|
|
|
<?php
|
2021-09-12 21:15:38 +08:00
|
|
|
declare(strict_types=1);
|
2021-07-08 22:28:51 +08:00
|
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
2021-08-31 22:33:41 +08:00
|
|
|
use App\Helpers\HashHelper;
|
2021-07-08 22:28:51 +08:00
|
|
|
use App\Model\Robot;
|
|
|
|
use App\Model\User;
|
|
|
|
use Hyperf\DbConnection\Db;
|
|
|
|
use Hyperf\Utils\Str;
|
|
|
|
|
|
|
|
class RobotService
|
|
|
|
{
|
2021-09-12 16:23:43 +08:00
|
|
|
/**
|
|
|
|
* 创建机器人
|
|
|
|
*
|
2021-07-08 22:28:51 +08:00
|
|
|
* @param array $data
|
|
|
|
* @return bool|array
|
|
|
|
*/
|
|
|
|
public function create(array $data)
|
|
|
|
{
|
|
|
|
Db::beginTransaction();
|
|
|
|
try {
|
|
|
|
$user = User::create([
|
|
|
|
'mobile' => '100' . mt_rand(1000, 9999) . mt_rand(1000, 9999),
|
2021-08-28 23:41:01 +08:00
|
|
|
'password' => HashHelper::make(Str::random(10)),
|
2021-07-08 22:28:51 +08:00
|
|
|
'is_robot' => 1
|
|
|
|
]);
|
|
|
|
|
|
|
|
$robot = Robot::create([
|
|
|
|
'user_id' => $user->id,
|
|
|
|
'robot_name' => $data['robot_name'],
|
|
|
|
'describe' => $data['describe'],
|
|
|
|
'logo' => $data['logo'],
|
|
|
|
'is_talk' => $data['is_talk'],
|
2021-09-12 16:23:43 +08:00
|
|
|
'type' => $data['type'],
|
2021-07-08 22:28:51 +08:00
|
|
|
'status' => 0,
|
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Db::rollBack();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $robot->toArray();
|
|
|
|
}
|
|
|
|
}
|