QrCodeController.class.php 1.85 KB
<?php
/**
 * 扫二维码签到
 * User: 蔡建华
 * Date: 17-9-1
 * Time: 下午7:55
 */

namespace Frontend\Controller\Index;

use Common\Service\PlanService;

class QrCodeController extends AbstractController
{

    // 可以签到
    const  PLAN_OPEN = 1;
    // 不在签到范围内
    const  PLAN_NOT_DATE = 2;
    // 没有签到计划
    const  PLAN_NOT_SIGN = 3;
    // 扫描签到
    const   IS_SIGN = 1;
    /** @var PlanService */
    protected $plan_s;

    public function before_action($action = '')
    {

        if (!parent::before_action($action)) {

            return false;
        }

        // 实例化培训计划service
        $this->plan_s = new PlanService();

        return true;
    }

    public function Index()
    {
        $ed_id = I('get.ed_id');
        // 签到计划
        $conds = [
            'ed_id' => $ed_id,
            'plan_type' => PlanService::PLAN_TYPE_SIGN
        ];
        $plan_id = 0;
        $data = $this->plan_s->list_by_conds($conds, null, null);
        // 不在签到范围内2
        $status = self::PLAN_NOT_DATE;
        if (empty($data)) {
            // 没有考勤计划
            $status = self::PLAN_NOT_SIGN;
        } else {

            foreach ($data as $val) {

                if (PlanService::PLAN_OPERATE_OPEN == $val['plan_use_status'] && $val['plan_sign_begin'] <= MILLI_TIME && $val['plan_sign_end'] >= MILLI_TIME) {
                    // 1
                    $status = self::PLAN_OPEN;
                    $plan_id = $val['plan_id'];
                    break;
                }
            }
        }


        // 扫二维码跳转签到地址
        redirectFront('/app/page/train/train-sign',
            [
                'ed_id' => $ed_id,
                'plan_id' => $plan_id,
                'status' => $status,
                'is_sign' => self::IS_SIGN
            ]);

    }
}