retail.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once(BASE_ROOT_PATH . '/vapi/control/sapi.php');
  3. class retailControl extends vbaseControl
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. private function check_params($params)
  10. {
  11. $channel_code = $params['channel_code'];
  12. if(empty($channel_code)) {
  13. return [false, "渠道信息有误."];
  14. }
  15. $province = $params['province'] ?? '';
  16. $city = $params['city'] ?? '';
  17. $area = $params['area'] ?? '';
  18. $address = $params['address'] ?? '';
  19. if(empty($province) || empty($city) || empty($area) || empty($address)) {
  20. return [false, "地址信息有误."];
  21. }
  22. $applicant_name = $params['applicant_name'];
  23. $contact_phone = $params['contact_phone'];
  24. if(empty($applicant_name) || empty($contact_phone)) {
  25. return [false, "联系人信息有误."];
  26. }
  27. if(!preg_match('/^1\d{10}$/', $contact_phone)) {
  28. return [false, "联系人电话格式有误."];
  29. }
  30. $retail = Model('')->table('retail')->where(['contact_phone' => $contact_phone])->find();
  31. if(!empty($retail)) {
  32. return [false, "此联系电话已申请过."];
  33. }
  34. $insert = [
  35. 'channel_code' => $channel_code, 'province' => $province, 'city' => $city, 'area' => $area,
  36. 'address' => $address, 'applicant_name' => $applicant_name, 'contact_phone' => $contact_phone,
  37. 'create_time' => time(), 'retail_sn' => $this->make_sn()
  38. ];
  39. return [true, $insert];
  40. }
  41. public function retail_recordOp()
  42. {
  43. [$success, $params] = $this->check_params($_POST);
  44. if ($success === false) {
  45. return self::outerr(300, $params);
  46. }
  47. $resp = Model('')->table('retail')->insert($params);
  48. if ($resp) {
  49. $sapi = new sapi();
  50. $body = ['pageId' => $_POST['pageId'], 'tid' => $_POST['tid'], 'lbid' => $_POST['lbid']];
  51. $resp = $sapi->send($body);
  52. Log::record("sapi result {$resp}", Log::DEBUG);
  53. return self::outsuccess([]);
  54. } else {
  55. return self::outerr(301, "录入信息失败.");
  56. }
  57. }
  58. private function make_sn()
  59. {
  60. return 'CARD' . mt_rand(1000, 9999)
  61. . sprintf('%010d', time())
  62. . sprintf('%06d', (float)microtime() * 1000000);
  63. }
  64. }