merchant_info.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. require_once(BASE_ROOT_PATH . '/mobile/control/merchantweb.php');
  3. class merchant_infoControl extends mbMerchantControl
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function indexOp()
  10. {
  11. $mchid = $this->mchid();
  12. $model_merchant = Model('merchant');
  13. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], 'mchid,admin_id,name,alarm_amount,ip_white_list,use_key,contact_name,contact_phone,warning_phone,company_name');
  14. $model_member = Model('member');
  15. $member_info = $model_member->getMemberInfo(['member_id' => $merchant_info['admin_id']], 'available_predeposit');
  16. if (empty($member_info)) {
  17. $member_info['available_predeposit'] = 0;
  18. }
  19. $merchant_info['member'] = $member_info;
  20. if (empty($merchant_info['ip_white_list'])) {
  21. $merchant_info['ips'] = [];
  22. } else {
  23. $merchant_info['ips'] = unserialize($merchant_info['ip_white_list']);
  24. }
  25. if (empty($merchant_info['warning_phone'])) {
  26. $merchant_info['warning_phone'] = [];
  27. } else {
  28. $merchant_info['warning_phone'] = unserialize($merchant_info['warning_phone']);
  29. }
  30. $cond['add_time'] = ['between', [strtotime(date("Y-m-d",time())), time()]];
  31. $cond['status'] = $cond['is_operation'] = 2;
  32. $cond['mchid'] = $mchid;
  33. $day_evidence = $model_merchant->getRefillEvidence($cond);
  34. $merchant_info['evidence_count'] = count($day_evidence);
  35. return self::outsuccess($merchant_info);
  36. }
  37. public function homeOp()
  38. {
  39. $mchid = $this->mchid();
  40. $model_merchant = Model('merchant');
  41. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], 'mchid,admin_id,name,company_name');
  42. $model_member = Model('member');
  43. $member_info = $model_member->getMemberInfo(['member_id' => $merchant_info['admin_id']], 'available_predeposit');
  44. if (empty($member_info)) {
  45. $merchant_info['available_predeposit'] = 0;
  46. } else {
  47. $merchant_info['available_predeposit'] = $member_info['available_predeposit'];
  48. }
  49. $statistics = $this->statistics();
  50. ksort($statistics);
  51. $result['merchant_info'] = $merchant_info;
  52. $result['todayStatistics'] = $statistics[strtotime(date("Y-m-d",time()))];
  53. $result['weeksStatistics'] = $statistics;
  54. $max = 0;
  55. foreach ($statistics as $key => $val){
  56. if($max == 0){
  57. $max = $val['count'];
  58. }
  59. if((int)$max < $val['count']){
  60. $max = $val['count'];
  61. }
  62. }
  63. $result['max'] = ceil($max * 1.1);
  64. return self::outsuccess($result);
  65. }
  66. private function statistics()
  67. {
  68. $date = date('Y-m-d',time());
  69. $today = strtotime("{$date}");
  70. $times_begin = function ($start) {
  71. $times = [];
  72. $begin = $start;
  73. for($i = 0; $i < 7; $i++) {
  74. $times[] = $begin;
  75. $begin -= 86400;
  76. }
  77. return $times;
  78. };
  79. $reader = function ($mchid,$time) {
  80. $cond['mchid'] = $mchid;
  81. $cond['inner_status'] = 0;
  82. $cond['refill_order.order_time'] = ['between', [$time, $time + 86400 -1]];
  83. $items = Model('')->table('refill_order,vr_order')->join('inner')
  84. ->on('refill_order.order_id=vr_order.order_id')
  85. ->field('count(*) as order_count, vr_order.order_state, sum(mch_amount) as mch_amounts')
  86. ->group('order_state')
  87. ->where($cond)->select();
  88. return $this->refillCountDispose($items);
  89. };
  90. $begins = $times_begin($today);
  91. $states = rcache($this->mchid() , 'refillstat-');
  92. if(empty($states)){
  93. $states = [];
  94. }else{
  95. $states = unserialize($states['data']);
  96. }
  97. $result = [];
  98. $cache = [];
  99. foreach ($begins as $begin)
  100. {
  101. if(array_key_exists($begin,$states)) {
  102. $item = $states[$begin];
  103. }
  104. else {
  105. $item = $reader($this->mchid(),$begin);
  106. }
  107. $result[$begin] = $item;
  108. //判断item 中充值中的状态是否为0,为0且不是今天的情况下放进cache
  109. if($item['sendCount'] == 0 && $begin != $today){
  110. $cache[$begin] = $item;
  111. }
  112. }
  113. if(!empty($cache) && !$this->isSame($states,$cache)) {
  114. wcache($this->mchid() ,['data' => serialize($cache)], 'refillstat-');
  115. }
  116. return $result;
  117. }
  118. private function isSame($arr1, $arr2)
  119. {
  120. ksort($arr1);
  121. ksort($arr2);
  122. return $arr1 == $arr2;
  123. }
  124. private function refillCountDispose($stats)
  125. {
  126. $result['count'] = $result['sendCount'] = $result['errorCount'] = $result['successCount'] = $result['amountCount'] = 0;
  127. foreach ($stats as $count) {
  128. $result['count'] += $count['order_count'];
  129. if($count['order_state'] == ORDER_STATE_SEND) {
  130. $result['sendCount'] = $count['order_count'];
  131. }
  132. if($count['order_state'] == ORDER_STATE_CANCEL) {
  133. $result['errorCount'] = $count['order_count'];
  134. }
  135. if($count['order_state'] == ORDER_STATE_SUCCESS) {
  136. $result['successCount'] = $count['order_count'];
  137. $result['amountCount'] = $count['mch_amounts'];
  138. }
  139. }
  140. return $result;
  141. }
  142. public function addipOp()
  143. {
  144. $mchid = $this->mchid();
  145. $ip = $_POST['ip'];
  146. if (empty($ip)) {
  147. return self::outerr(errcode::ErrParamter, "参数错误");
  148. }
  149. $ip = trim($ip);
  150. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
  151. {
  152. $model_merchant = Model('merchant');
  153. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  154. if (empty($merchant_info['ip_white_list'])) {
  155. $ips = [];
  156. } else {
  157. $ips = unserialize($merchant_info['ip_white_list']);
  158. }
  159. $ips[] = $ip;
  160. $ips = array_unique($ips);
  161. $model_merchant->editMerchant(['ip_white_list' => serialize($ips)], ['mchid' => $merchant_info['mchid']]);
  162. return self::outsuccess([]);
  163. } else {
  164. return self::outerr(errcode::ErrParamter, "ip地址错误");
  165. }
  166. }
  167. public function ipdelOp()
  168. {
  169. $mchid = $this->mchid();
  170. $ip = $_POST['ip'];
  171. if (empty($ip)) {
  172. return self::outerr(errcode::ErrParamter, "参数错误");
  173. }
  174. $ip = trim($ip);
  175. $model_merchant = Model('merchant');
  176. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  177. $ips = unserialize($merchant_info['ip_white_list']);
  178. $new_ips = [];
  179. foreach ($ips as $value) {
  180. if ($value != $ip) {
  181. $new_ips[] = $value;
  182. }
  183. }
  184. if (empty($new_ips)) {
  185. $new_ips = '';
  186. } else {
  187. $new_ips = serialize($new_ips);
  188. }
  189. $model_merchant->editMerchant(['ip_white_list' => $new_ips], ['mchid' => $merchant_info['mchid']]);
  190. return self::outsuccess([]);
  191. }
  192. public function setcontactOp(){
  193. $mchid = $this->mchid();
  194. if(!empty($_POST['contact_name']))
  195. {
  196. $params['contact_name'] = trim($_POST['contact_name']);
  197. }
  198. if(!empty($_POST['contact_phone']))
  199. {
  200. $params['contact_phone'] = trim($_POST['contact_phone']);
  201. }
  202. if(!empty($_POST['alarm_amount']))
  203. {
  204. $params['alarm_amount'] = trim($_POST['alarm_amount']);
  205. }
  206. if(empty($params))
  207. {
  208. return self::outsuccess([]);
  209. }
  210. $model_merchant = Model('merchant');
  211. $ret = $model_merchant->editMerchant($params, ['mchid' => $mchid]);
  212. if ($ret) {
  213. return self::outsuccess([]);
  214. } else {
  215. return self::outerr(errcode::ErrOperation, "系统错误.");
  216. }
  217. }
  218. public function addwphoneOp()
  219. {
  220. $mchid = $this->mchid();
  221. $phone = $_POST['phone'];
  222. if (empty($phone)) {
  223. return self::outerr(errcode::ErrParamter, "参数错误");
  224. }
  225. $phone = explode(',' ,trim($phone));
  226. $model_merchant = Model('merchant');
  227. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  228. if (empty($merchant_info['warning_phone'])) {
  229. $phones = [];
  230. } else {
  231. $phones = unserialize($merchant_info['warning_phone']);
  232. }
  233. foreach ($phone as $item) {
  234. $phones[] = $item;
  235. }
  236. $phones = array_unique($phones);
  237. $model_merchant->editMerchant(['warning_phone' => serialize($phones)], ['mchid' => $merchant_info['mchid']]);
  238. return self::outsuccess([]);
  239. }
  240. public function wphonedelOp()
  241. {
  242. $mchid = $this->mchid();
  243. $phone = $_POST['phone'];
  244. if (empty($phone)) {
  245. return self::outerr(errcode::ErrParamter, "参数错误");
  246. }
  247. $phone = trim($phone);
  248. $model_merchant = Model('merchant');
  249. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  250. $phones = unserialize($merchant_info['warning_phone']);
  251. $new_phones = [];
  252. foreach ($phones as $value) {
  253. if ($value != $phone) {
  254. $new_phones[] = $value;
  255. }
  256. }
  257. if (empty($new_phones)) {
  258. $new_phones = '';
  259. } else {
  260. $new_phones = serialize($new_phones);
  261. }
  262. $model_merchant->editMerchant(['warning_phone' => $new_phones], ['mchid' => $merchant_info['mchid']]);
  263. return self::outsuccess([]);
  264. }
  265. public function setkeyOp()
  266. {
  267. $mchid = $this->mchid();
  268. $secure_key = $_POST['secure_key'];
  269. if (empty($secure_key)) {
  270. return self::outerr(errcode::ErrParamter, "参数错误");
  271. }
  272. $model_merchant = Model('merchant');
  273. $ret = $model_merchant->editMerchant(['secure_key' => $secure_key, 'use_key' => 1], ['mchid' => $mchid]);
  274. if ($ret) {
  275. return self::outsuccess([]);
  276. } else {
  277. return self::outerr(errcode::ErrOperation, "系统错误.");
  278. }
  279. }
  280. public function modifypwOp()
  281. {
  282. $mchid = $this->mchid();
  283. $new_pw = $_POST['new_pw'];
  284. $new_pw2 = $_POST['new_pw2'];
  285. if (trim($new_pw) !== trim($new_pw2)) {
  286. return self::outerr(errcode::ErrPasswd, "密码错误");
  287. }
  288. $model_merchant = Model('merchant');
  289. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  290. if (!$merchant_info) {
  291. return self::outerr(errcode::ErrMemberNotExist, "用户不存在.");
  292. }
  293. $pwd = trim($new_pw);
  294. if (md5($pwd) == $merchant_info['password']) {
  295. return self::outsuccess([]);
  296. }
  297. $ret = $model_merchant->editMerchant(['password' => md5($pwd), 'org_pwd' => $pwd], ['mchid' => $merchant_info['mchid']]);
  298. if ($ret) {
  299. return self::outsuccess([]);
  300. } else {
  301. return self::outerr(errcode::ErrOperation, "系统错误.");
  302. }
  303. }
  304. public function pdlogOp()
  305. {
  306. $mchid = $this->mchid();
  307. $model_merchant = Model('merchant');
  308. $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
  309. if (!$merchant_info) {
  310. return self::outerr(errcode::ErrMemberNotExist, "用户不存在.");
  311. }
  312. $model_pd = Model('merchant');
  313. if (empty($merchant_info['admin_id'])) {
  314. $result['data'] = [];
  315. $result['total'] = 0;
  316. return self::outsuccess($result);
  317. }
  318. $cond['lg_member_id'] = $merchant_info['admin_id'];
  319. if (!empty($_GET['lg_type'])) {
  320. $cond['lg_type'] = $_GET['lg_type'];
  321. }
  322. if ($_GET['start_time'] && $_GET['end_time']) {
  323. $cond['lg_add_time'] = ['between', [$_GET['start_time'], $_GET['end_time']]];
  324. }
  325. $list = $model_pd->getPdlog($cond, $this->page, '*', 'lg_id desc');
  326. $list = $this->PdLogFormat($list);
  327. $result['data'] = $list;
  328. $result['total'] = $model_pd->gettotalpage();
  329. return self::outsuccess($result);
  330. }
  331. private function PdLogFormat($pdlog)
  332. {
  333. $data = [];
  334. foreach ($pdlog as $key => $value) {
  335. if (isset($value['lg_add_time'])) {
  336. $value['lg_add_time'] = date('Y-m-d H:i:s', $value['lg_add_time']);
  337. }
  338. switch ($value['lg_type']) {
  339. case 'order_pay':
  340. $value['lg_type_text'] = '下单减款';
  341. break;
  342. case 'order_cancel':
  343. $value['lg_type_text'] = '下单失败返回余款';
  344. break;
  345. case 'recharge':
  346. $value['lg_type_text'] = '余款充值';
  347. break;
  348. case 'sys_add_money':
  349. $value['lg_type_text'] = '管理员调节预存款【增加】';
  350. break;
  351. case 'sys_del_money':
  352. $value['lg_type_text'] = '管理员调节预存款【减少】';
  353. break;
  354. case 'sys_freeze_money':
  355. $value['lg_type_text'] = '管理员调节预存款【冻结】';
  356. break;
  357. case 'sys_unfreeze_money':
  358. $value['lg_type_text'] = '管理员调节预存款【解冻】';
  359. break;
  360. default:
  361. $value['lg_type_text'] = 'unknown';
  362. break;
  363. }
  364. $data[] = $value;
  365. }
  366. return $data;
  367. }
  368. }