MobileSeller.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 控制器
  10. */
  11. class MobileSeller extends MobileHome
  12. {
  13. protected $seller_info = array();
  14. protected $seller_group_info = array();
  15. protected $member_info = array();
  16. protected $store_info = array();
  17. protected $store_grade = array();
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/baseseller.lang.php');
  22. $mbsellertoken_model = model('mbsellertoken');
  23. $key = request()->header('X-DS-KEY');
  24. if (empty($key)) {
  25. ds_json_encode(13001, lang('please_login'), array('login' => '0'));
  26. }
  27. $mb_seller_token_info = $mbsellertoken_model->getMbsellertokenInfoByToken($key);
  28. if (empty($mb_seller_token_info)) {
  29. ds_json_encode(13001, lang('please_login'), array('login' => '0'));
  30. }
  31. $seller_model = model('seller');
  32. $member_model = model('member');
  33. $store_model = model('store');
  34. $sellergroup_model = model('sellergroup');
  35. $this->seller_info = $seller_model->getSellerInfo(array('seller_id' => $mb_seller_token_info['seller_id']));
  36. $this->member_info = $member_model->getMemberInfoByID($this->seller_info['member_id']);
  37. $this->store_info = $store_model->getStoreInfoByID($this->seller_info['store_id']);
  38. $this->seller_group_info = $sellergroup_model->getSellergroupInfo(array('sellergroup_id' => $this->seller_info['sellergroup_id']));
  39. if (!is_array($this->seller_group_info)) {
  40. $this->seller_group_info = array();
  41. }
  42. // 店铺等级
  43. if (intval($this->store_info['is_platform_store']) === 1) {
  44. $this->store_grade = array(
  45. 'storegrade_id' => '0',
  46. 'storegrade_name' => lang('store_grade_ownshop'),
  47. 'storegrade_goods_limit' => '0',
  48. 'storegrade_album_limit' => '0',
  49. 'storegrade_space_limit' => '999999999',
  50. 'storegrade_template_number' => '6',
  51. 'storegrade_price' => '0.00',
  52. 'storegrade_description' => '',
  53. 'storegrade_sort' => '255',
  54. );
  55. } else {
  56. $store_grade = rkcache('storegrade', true);
  57. $this->store_grade = $store_grade[$this->store_info['grade_id']];
  58. }
  59. if (empty($this->member_info)) {
  60. ds_json_encode(13001, lang('please_login'), array('login' => '0'));
  61. } else {
  62. $this->seller_info['seller_clienttype'] = $mb_seller_token_info['seller_clienttype'];
  63. }
  64. $seller_model->createSellerSession($this->member_info, $this->store_info, $this->seller_info, $this->seller_group_info);
  65. if ($this->seller_info['is_admin'] !== 1 && request()->controller() !== 'Sellerindex' && request()->controller() !== 'Sellerlogout' && !(request()->controller() == 'Sellergoodsclass' && request()->action() == 'get_tree')) {
  66. $seller_limits = isset($this->seller_group_info['sellergroup_limits']) ? explode('|', $this->seller_group_info['sellergroup_limits']) : '';
  67. if (!in_array(request()->controller(), $seller_limits)) {
  68. ds_json_encode(10001, lang('have_no_legalpower'));
  69. }
  70. }
  71. }
  72. /**
  73. * 记录卖家日志
  74. *
  75. * @param $content 日志内容
  76. * @param $state 1成功 0失败
  77. */
  78. protected function recordSellerlog($content = '', $state = 1)
  79. {
  80. $seller_info = array();
  81. $seller_info['sellerlog_content'] = $content;
  82. $seller_info['sellerlog_time'] = TIMESTAMP;
  83. $seller_info['sellerlog_seller_id'] = $this->seller_info['seller_id'];
  84. $seller_info['sellerlog_seller_name'] = $this->seller_info['seller_name'];
  85. $seller_info['sellerlog_store_id'] = $this->store_info['store_id'];
  86. $seller_info['sellerlog_seller_ip'] = request()->ip();
  87. $seller_info['sellerlog_url'] = 'home/' . request()->controller() . '/' . request()->action();
  88. $seller_info['sellerlog_state'] = $state;
  89. $sellerlog_model = model('sellerlog');
  90. $sellerlog_model->addSellerlog($seller_info);
  91. }
  92. /**
  93. * 记录店铺费用
  94. *
  95. * @param $storecost_price 费用金额
  96. * @param $storecost_remark 费用备注
  97. */
  98. protected function recordStorecost($storecost_price, $storecost_remark)
  99. {
  100. // 平台店铺不记录店铺费用
  101. if ($this->store_info['is_platform_store']) {
  102. return false;
  103. }
  104. $storecost_model = model('storecost');
  105. $param = array();
  106. $param['storecost_store_id'] = $this->store_info['store_id'];
  107. $param['storecost_seller_id'] = $this->seller_info['seller_id'];
  108. $param['storecost_price'] = $storecost_price;
  109. $param['storecost_remark'] = $storecost_remark;
  110. $param['storecost_state'] = 0;
  111. $param['storecost_time'] = TIMESTAMP;
  112. $storecost_model->addStorecost($param);
  113. // 发送店铺消息
  114. $param = array();
  115. $param['code'] = 'store_cost';
  116. $param['store_id'] = $this->store_info['store_id'];
  117. $param['ali_param'] = array(
  118. 'price' => $storecost_price,
  119. 'seller_name' => $this->seller_info['seller_name'],
  120. 'remark' => $storecost_remark
  121. );
  122. $param['ten_param'] = array(
  123. $storecost_price,
  124. $this->seller_info['seller_name'],
  125. $storecost_remark
  126. );
  127. $param['param'] = $param['ali_param'];
  128. //微信模板消息
  129. $param['weixin_param'] = array(
  130. 'url' => config('ds_config.h5_store_site_url') . '/pages/seller/cost/CostList',
  131. 'data' => array(
  132. "keyword1" => array(
  133. "value" => $storecost_price,
  134. "color" => "#333"
  135. ),
  136. "keyword2" => array(
  137. "value" => date('Y-m-d H:i'),
  138. "color" => "#333"
  139. )
  140. ),
  141. );
  142. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'sendStoremsg', 'cron_value' => serialize($param)));
  143. }
  144. }