123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- require_once(BASE_ROOT_PATH . '/vapi/control/sapi.php');
- class retailControl extends vbaseControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- private function check_params($params)
- {
- $channel_code = $params['channel_code'];
- if(empty($channel_code)) {
- return [false, "渠道信息有误."];
- }
- $province = $params['province'] ?? '';
- $city = $params['city'] ?? '';
- $area = $params['area'] ?? '';
- $address = $params['address'] ?? '';
- if(empty($province) || empty($city) || empty($area) || empty($address)) {
- return [false, "地址信息有误."];
- }
- $applicant_name = $params['applicant_name'];
- $contact_phone = $params['contact_phone'];
- if(empty($applicant_name) || empty($contact_phone)) {
- return [false, "联系人信息有误."];
- }
- if(!preg_match('/^1\d{10}$/', $contact_phone)) {
- return [false, "联系人电话格式有误."];
- }
- $retail = Model('')->table('retail')->where(['contact_phone' => $contact_phone])->find();
- if(!empty($retail)) {
- return [false, "此联系电话已申请过."];
- }
- $id_card = $_POST['id_card'];
- if (!preg_match('#^\d{17}(\d|X)$#', $id_card)) {
- return [false, "身份证号格式错误."];
- }
- $insert = [
- 'channel_code' => $channel_code, 'province' => $province, 'city' => $city, 'area' => $area,
- 'address' => $address, 'applicant_name' => $applicant_name, 'contact_phone' => $contact_phone,
- 'id_card' => $id_card, 'create_time' => time(), 'retail_sn' => $this->make_sn()
- ];
- return [true, $insert];
- }
- public function retail_recordOp()
- {
- [$success, $params] = $this->check_params($_POST);
- if ($success === false) {
- return self::outerr(300, $params);
- }
- $resp = Model('')->table('retail')->insert($params);
- if ($resp) {
- $sapi = new sapi();
- $body = ['pageId' => $_POST['pageId'], 'tid' => $_POST['tid'], 'lbid' => $_POST['lbid']];
- $resp = $sapi->send($body);
- Log::record("sapi result {$resp}", Log::DEBUG);
- return self::outsuccess([]);
- } else {
- return self::outerr(301, "录入信息失败.");
- }
- }
- private function make_sn()
- {
- return 'CARD' . mt_rand(1000, 9999)
- . sprintf('%010d', time())
- . sprintf('%06d', (float)microtime() * 1000000);
- }
- }
|