StoreApplicationModel.class.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Common\Model;
  3. use Common\Model\BaseModel;
  4. /**
  5. * 加盟申请
  6. * @author: linch
  7. * Class StoreApplicationModel
  8. * @package Common\Model
  9. */
  10. class StoreApplicationModel extends BaseModel
  11. {
  12. //使用x-motion.cn数据库
  13. protected $connection ='DB_CONFIG_XMOTION';
  14. protected $mod;
  15. //状态
  16. const status_wait = 0; //待处理
  17. const status_processed = 1; //已联系
  18. //软删状态
  19. const flag_off = 0; //删除
  20. const flag_on = 1; //正常
  21. //来源
  22. const source_mini_app = 0; //小程序
  23. const source_official_web = 1; //官网
  24. const source_official_wap = 2; //wap端
  25. public function __construct() {
  26. parent::__construct();
  27. $this->mod = M('store_application');
  28. }
  29. /**
  30. * 添加加盟信息
  31. * @author: linch
  32. * @param $data
  33. * @param $source
  34. * @param $ad_message_id
  35. * @return array
  36. */
  37. public function data_add($data, $source, $ad_message_id = 0) {
  38. $time = date('Y-m-d H:i:s');
  39. $save_data = array(
  40. 'name' => $data['name'],
  41. 'tel' => $data['tel'],
  42. 'mail' => trim($data['mail']),
  43. 'intention' => trim($data['intention']),
  44. 'city' => trim($data['city']),
  45. 'content' => trim($data['content']),
  46. 'source' => $source,
  47. 'status' => self::status_wait,
  48. 'flag' => self::flag_on,
  49. 'u_time' => $time,
  50. 'c_time' => $time,
  51. );
  52. if (!empty($ad_message_id)) {
  53. $save_data['ad_message_id'] = (int)$ad_message_id;
  54. }
  55. $result = $this->check_edit_data($save_data);
  56. if ($result['code'] != 1000) {
  57. $msg = array('code' => $result['code'], 'msg' => $result['msg']);
  58. } else {
  59. $id = $this->data($save_data)->add();
  60. if ($id == false) {
  61. $msg = array('code' => 1005, 'msg' => '内部错误,稍后重试');
  62. } else {
  63. $msg = array('code' => 1000, 'msg' => '提交成功');
  64. }
  65. }
  66. return $msg;
  67. }
  68. /**
  69. * 验证数据
  70. * @author: linch
  71. * @param $data
  72. * @return array
  73. */
  74. public function check_edit_data($data) {
  75. if (empty($data['name'])) {
  76. return array('code' => 1001, 'msg' => '姓名不能为空');
  77. }
  78. if (empty($data['tel'])) {
  79. return array('code' => 1001, 'msg' => '手机不能为空');
  80. }
  81. //官网web和wap端单独验证规则
  82. if ($data['source'] == self::source_official_web || $data['source'] == self::source_official_wap) {
  83. if (empty($data['content'])) {
  84. return array('code' => 1001, 'msg' => '留言不能为空');
  85. }
  86. }
  87. //小程序单独验证规则
  88. if ($data['source'] == self::source_mini_app) {
  89. if (empty($data['mail'])) {
  90. return array('code' => 1001, 'msg' => '邮箱不能为空');
  91. }
  92. }
  93. if (!preg_match('/^[1][3,4,5,7,8][0-9]{9}$/', $data['tel'])) {
  94. return array('code' => 1006, 'msg' => '手机号错误');
  95. }
  96. return array('code' => 1000, 'msg' => '数据符合');
  97. }
  98. }