123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace App\Http\Controllers\Experience;
- use App\Models\Wechat\FormIdModel;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class TuodanController extends Controller
- {
- //
- public function index(Request $request)
- {
- $openid = $request->openid;
- $options = $request->options;
- $score = $this->option($options);
- $data = $this->result($score);
- \DB::table('kdgx_mini_tuodan')->insert([
- 'openid' => $openid,
- 'created_at' => time(),
- 'updated_at' => time(),
- 'data' => json_encode($data)
- ]);
- return [
- 'code' => 200,
- 'message' => 'OK',
- 'data' => $data
- ];
- }
- /**
- * 计算选项得分
- */
- private function option(array $options)
- {
- $score = 0;
- foreach ($options as $key => $option) {
- switch ($key) {
- case '1':
- switch ($option) {
- case '0':
- case '1':
- break;
- }
- break;
- case '2':
- switch ($option) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- break;
- }
- break;
- case '3':
- switch ($option) {
- case '0':
- $score += 30;
- break;
- case '1':
- $score += 10;
- break;
- }
- break;
- case '4':
- switch ($option) {
- case '0':
- $score += 10;
- break;
- case '1':
- $score += 30;
- break;
- }
- break;
- case '5':
- switch ($option) {
- case '0':
- break;
- case '1':
- $score += 30;
- break;
- }
- break;
- case '6':
- switch ($option) {
- case '0':
- case '1':
- break;
- }
- break;
- }
- }
- return $score;
- }
- public function result(int $score)
- {
- switch ($score) {
- case '20':
- $type = rand(2, 4);
- $day = 0;
- break;
- case '40':
- case '30':
- $type = 1;
- $day = rand(361, 1800);
- break;
- case '60':
- case '70':
- $type = 1;
- $day = rand(31, 360);
- break;
- case '90':
- $type = 1;
- $day = rand(1, 30);
- break;
- default:
- $type = rand(2, 4);
- $day = 0;
- }
- $list = array("游戏里", "聚会", "婚礼", "健身房", "美食街", "学校", "旅行中", "商场", "咖啡厅", "公园", "公交车", "地铁里");
- $key = array_rand($list);
- $place = $list[$key];
- return [
- 'type' => $type,
- 'day' => $day,
- 'place' => $place
- ];
- }
- /**
- * 几率formId
- * @param Request $request
- * @return array
- */
- public function form(Request $request)
- {
- $this->validate($request, [
- 'form_id' => 'required',
- 'openid' => 'required',
- 'public_id' => 'required',
- ]);
- FormIdModel::create($request->all());
- return [
- 'code' => 200,
- 'message' => 'OK'
- ];
- }
- public function info()
- {
- return [
- 'code' => 200,
- 'message' => 'OK',
- 'data' => [
- 'is_qrcode' => 0,
- ]
- ];
- }
- }
|