StoreApplicationModel.class.php 3.1 KB

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