content-provider.ctrl.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. $_W['page']['title'] = '系统-流量主';
  7. $dos = array('flow_control', 'finance_info', 'register_flow', 'display', 'account_list', 'ad_type_get', 'content_provider');
  8. $do = in_array($do, $dos) ? $do : 'account_list';
  9. load()->model('cloud');
  10. load()->func('file');
  11. $flow_master_info = cloud_flow_master_get();
  12. $flow_uniaccount_list = cloud_flow_uniaccount_list_get();
  13. if (isset($flow_master_info['site_key']) && $flow_master_info['site_key'] == '0') {
  14. itoast('请注册站点或者重置站点信息', referer(), 'error');
  15. }
  16. $commission_show = false;
  17. if (!empty($flow_uniaccount_list)) {
  18. foreach ($flow_uniaccount_list as $val) {
  19. if (!empty($val['ad_tags']) && is_array($val['ad_tags'])) {
  20. $commission_show = true;
  21. }
  22. }
  23. }
  24. $status = cloud_prepare();
  25. if (is_error($status)) {
  26. itoast($status['message'], url('cloud/profile'), 'error');
  27. }
  28. if ($do == 'display') {
  29. if ($flow_master_info['status'] == 4 || IMS_FAMILY == 'v') {
  30. header('Location:' . url('advertisement/content-provider/account_list'));
  31. exit;
  32. }
  33. }
  34. if ($do == 'register_flow') {
  35. if (($flow_master_info['status'] == 4 || IMS_FAMILY == 'v') || $flow_master_info['status'] == 2) {
  36. itoast('权限不足', url('advertisement/content-provider/account_list'), 'error');
  37. }
  38. if (checksubmit('submit')) {
  39. $linkman = trim($_GPC['linkman']);
  40. $mobile = trim($_GPC['mobile']);
  41. $address = trim($_GPC['address']);
  42. if (empty($linkman)) {
  43. itoast('联系人不能为空', referer(), 'error');
  44. }
  45. if (empty($mobile)) {
  46. itoast('电话不能为空', referer(), 'error');
  47. } else {
  48. if(!preg_match(REGULAR_MOBILE, $mobile)) {
  49. itoast('手机号格式不正确', referer(), 'error');
  50. }
  51. }
  52. if (empty($address)) {
  53. itoast('联系地址不能为空', referer(), 'error');
  54. }
  55. if (!empty($_FILES['id_card_photo']['tmp_name'])) {
  56. $_W['uploadsetting'] = array();
  57. $_W['uploadsetting']['image']['folder'] = '';
  58. $_W['uploadsetting']['image']['extentions'] = array('jpg');
  59. $_W['uploadsetting']['image']['limit'] = $_W['config']['upload']['image']['limit'];
  60. $upload = file_upload($_FILES['id_card_photo'], 'image', "id_card");
  61. $id_card_photo = $upload['path'];
  62. if(is_error($upload)) {
  63. itoast('身份证保存失败,'.$upload['message'],referer(),'info');
  64. }
  65. }
  66. if (!empty($_FILES['business_licence_photo']['tmp_name'])) {
  67. $_W['uploadsetting'] = array();
  68. $_W['uploadsetting']['image']['folder'] = '';
  69. $_W['uploadsetting']['image']['extentions'] = array('jpg');
  70. $_W['uploadsetting']['image']['limit'] = $_W['config']['upload']['image']['limit'];
  71. $upload = file_upload($_FILES['business_licence_photo'], 'image', "business_licence");
  72. $business_licence_photo = $upload['path'];
  73. if(is_error($upload)) {
  74. itoast('营业执照保存失败,'.$upload['message'], referer(), 'info');
  75. }
  76. }
  77. if (!empty($flow_master_info['id_card_photo']) && empty($id_card_photo)) {
  78. $id_card_photo = $flow_master_info['id_card_photo'];
  79. }
  80. if (!empty($flow_master_info['business_licence_photo']) && empty($business_licence_photo)) {
  81. $business_licence_photo = $flow_master_info['business_licence_photo'];
  82. }
  83. $flow_master = array(
  84. 'linkman' => trim($_GPC['linkman']),
  85. 'mobile' => trim($_GPC['mobile']),
  86. 'address' => trim($_GPC['address']),
  87. 'id_card_photo' => tomedia($id_card_photo),
  88. 'business_licence_photo' => tomedia($business_licence_photo),
  89. );
  90. $result = cloud_flow_master_post($flow_master);
  91. if (is_error($result)) {
  92. itoast($result['message'], '', 'error');
  93. } else {
  94. itoast('提交成功,请等待审核', url('advertisement/content-provider/display'), 'info');
  95. }
  96. }
  97. }
  98. if ($do == 'account_list') {
  99. if ($flow_master_info['status'] != 4 && IMS_FAMILY != 'v') {
  100. header('Location:' . url('advertisement/content-provider/display'));
  101. exit;
  102. }
  103. $pindex = max(1, intval($_GPC['page']));
  104. $psize = 15;
  105. $start = ($pindex - 1) * $psize;
  106. $condition = '';
  107. $pars = array();
  108. $keyword = trim($_GPC['keyword']);
  109. $s_uniacid = intval($_GPC['s_uniacid']);
  110. if (!empty($_W['isfounder'])) {
  111. $condition .= " WHERE a.default_acid <> 0 AND b.isdeleted <> 1";
  112. $order_by = " ORDER BY a.`rank` DESC";
  113. } else {
  114. $condition .= "LEFT JOIN ". tablename('uni_account_users')." as c ON a.uniacid = c.uniacid WHERE a.default_acid <> 0 AND c.uid = :uid AND b.isdeleted <> 1";
  115. $pars[':uid'] = $_W['uid'];
  116. $order_by = " ORDER BY c.`rank` DESC";
  117. }
  118. if(!empty($keyword)) {
  119. $condition .=" AND a.`name` LIKE :name";
  120. $pars[':name'] = "%{$keyword}%";
  121. }
  122. if(!empty($s_uniacid)) {
  123. $condition .=" AND a.`uniacid` = :uniacid";
  124. $pars[':uniacid'] = $s_uniacid;
  125. }
  126. if(!empty($_GPC['expiretime'])) {
  127. $expiretime = intval($_GPC['expiretime']);
  128. $condition .= " AND a.`uniacid` IN(SELECT uniacid FROM " .tablename('uni_account_users') . " WHERE role = 'owner' AND uid IN (SELECT uid FROM " .tablename('users'). " WHERE endtime > :time AND endtime < :endtime))";
  129. $pars[':time'] = time();
  130. $pars[':endtime'] = strtotime(date('Y-m-d', time()+86400*($expiretime+2)));
  131. }
  132. if ($_GPC['type'] == '3') {
  133. $condition .= " AND b.type = 3";
  134. } elseif ($_GPC['type'] == '1') {
  135. $condition .= " AND b.type <> 3";
  136. }
  137. $tsql = "SELECT COUNT(*) FROM " . tablename('uni_account'). " as a LEFT JOIN". tablename('account'). " as b ON a.default_acid = b.acid {$condition} {$order_by}, a.`uniacid` DESC";
  138. $total = pdo_fetchcolumn($tsql, $pars);
  139. $sql = "SELECT * FROM ". tablename('uni_account'). " as a LEFT JOIN". tablename('account'). " as b ON a.default_acid = b.acid {$condition} {$order_by}, a.`uniacid` DESC LIMIT {$start}, {$psize}";
  140. $pager = pagination($total, $pindex, $psize);
  141. $list = pdo_fetchall($sql, $pars, 'uniacid');
  142. $flow_uniaccount_list = cloud_flow_uniaccount_list_get();
  143. if(!empty($list)) {
  144. foreach($list as $unia => &$account) {
  145. $account_details = uni_accounts($account['uniacid']);
  146. $account['details'][$account['default_acid']] = $account_details[$account['default_acid']];
  147. $account['role'] = permission_account_user_role($_W['uid'], $account['uniacid']);
  148. $account['setmeal'] = uni_setmeal($account['uniacid']);
  149. if (!empty($flow_uniaccount_list[$unia])) {
  150. $flow_uniaccount_list[$unia]['ad_tags_str'] = @implode($flow_uniaccount_list[$unia]['ad_tags'], ',');
  151. $flow_uniaccount_list[$unia]['amount'] = $flow_uniaccount_list[$unia]['amount'] / 100;
  152. $account['flow_setting'] = $flow_uniaccount_list[$unia];
  153. $account['flow_setting_enable'] = $flow_uniaccount_list[$unia]['enable'];
  154. } else {
  155. $account['flow_setting_enable'] = 1;
  156. }
  157. }
  158. }
  159. }
  160. if ($do == 'flow_control') {
  161. if (empty($_GPC['uniacid'])) {
  162. itoast('公众号id参数有误,请重新进入', url('advertisement/content-provider/account_list'), 'error');
  163. }
  164. $current_account = uni_fetch($_GPC['uniacid']);
  165. load() -> model('account');
  166. $_W['uniacid'] = $_GPC['uniacid'];
  167. $installedmodulelist = uni_modules();
  168. foreach ($installedmodulelist as $val) {
  169. if ($val['issystem'] == 0 && $val['enabled'] == 1) {
  170. $path = '../addons/' . $val['name'];
  171. $cion = $path . '/icon-custom.jpg';
  172. if(!file_exists($cion)) {
  173. $cion = $path . '/icon.jpg';
  174. if(!file_exists($cion)) {
  175. $cion = './resource/images/nopic-small.jpg';
  176. }
  177. }
  178. $val['icon'] = $cion;
  179. $modulelist[$val['name']] = $val;
  180. $modulenames[] = $val['name'];
  181. }
  182. }
  183. $cloud_module_support = cloud_flow_app_support_list($modulenames);
  184. $cloud_module_support_str = json_encode($cloud_module_support);
  185. $flow_app_list_setting = cloud_flow_app_list_get($current_account['uniacid']);
  186. if (!empty($flow_app_list_setting)) {
  187. foreach ($flow_app_list_setting as &$value) {
  188. $value['ad_types'] = iunserializer($value['ad_types']);
  189. }
  190. }
  191. if (!empty($cloud_module_support)) {
  192. foreach ($cloud_module_support as $support) {
  193. if ($support['ad_support'] == 2) {
  194. $modulelist_available[$support['name']] = $modulelist[$support['name']];
  195. $modulelist_available[$support['name']]['flow_setting'] = $flow_app_list_setting[$support['name']];
  196. $modulelist_available[$support['name']]['ad_types'] = json_encode($support['ad_types']);
  197. }
  198. }
  199. }
  200. $tag_list = cloud_flow_ad_tag_list();
  201. if (!empty($tag_list)) {
  202. foreach ($tag_list as $value) {
  203. foreach ($value['items'] as $key => $item) {
  204. $items[$key] = $item;
  205. }
  206. }
  207. }
  208. $current_uniaccount = cloud_flow_uniaccount_get($current_account['uniacid']);
  209. if (!empty($current_uniaccount)) {
  210. $current_tags = iunserializer($current_uniaccount['ad_tags']);
  211. $current_uniaccount['current_tags_str'] = @implode($current_tags, ',');
  212. $current_uniaccount['amount'] = $current_uniaccount['amount'] / 100;
  213. }
  214. $ad_type_lists = cloud_flow_ad_type_list();
  215. if ($_W['isajax'] && $_W['ispost']) {
  216. if ($_GPC['type'] == 'tags') {
  217. if ($_GPC['enable'] == 2) {
  218. if (!empty($_GPC['tagids'])) {
  219. foreach ($_GPC['tagids'] as $value) {
  220. $ad_tags[$value] = $items[$value];
  221. }
  222. } else {
  223. iajax(1, '请至少选择一个标签', '');
  224. }
  225. }
  226. $uniacid = intval($_GPC['uniacid']);
  227. $uniaccount['uniacid'] = intval($_GPC['uniacid']);
  228. if ($_GPC['enable'] == 1) {
  229. $uniaccount['enable'] = 1;
  230. } elseif ($_GPC['enable'] == 2) {
  231. $uniaccount['title'] = trim($current_account['name']);
  232. $uniaccount['original'] = trim($current_account['original']);
  233. $uniaccount['gh_type'] = trim($current_account['level']);
  234. $uniaccount['ad_tags'] = $ad_tags;
  235. $uniaccount['enable'] = 2;
  236. }
  237. $result = cloud_flow_uniaccount_post($uniaccount);
  238. } elseif ($_GPC['type'] == 'types') {
  239. $uniacid = intval($_GPC['uniacid']);
  240. $module_name = trim($_GPC['module_name']);
  241. if (!empty($_GPC['typeids'])) {
  242. foreach ($_GPC['typeids'] as $value) {
  243. $ad_types[$value] = $ad_type_lists[$value]['title'];
  244. }
  245. $result = cloud_flow_app_post($uniacid, $module_name, '2', $ad_types);
  246. } else {
  247. $result = cloud_flow_app_post($uniacid, $module_name, '1', array(''));
  248. }
  249. }
  250. if (!is_error($result)) {
  251. iajax(0, '设置成功', referer());
  252. } else {
  253. iajax(-1, $result['message'], '');
  254. }
  255. }
  256. }
  257. if ($do == 'ad_type_get') {
  258. $module_name = trim($_GPC['module_name']);
  259. $uniacid = intval($_GPC['uniacid']);
  260. $flow_app_list_setting = cloud_flow_app_list_get($uniacid);
  261. $current_app_set = $flow_app_list_setting[$module_name];
  262. if (!is_error($current_app_set)) {
  263. iajax(0, $current_app_set['ad_types'], '');
  264. } else {
  265. iajax(-1, $result['message'], '');
  266. }
  267. }
  268. if ($do == 'finance_info') {
  269. if (empty($commission_show)) {
  270. itoast('权限不足', url('advertisement/content-provider/account_list'), 'error');
  271. }
  272. $params = array(
  273. 'size' => '15',
  274. 'page' => $_GPC['page'],
  275. );
  276. if (!empty($_GPC['type'])) {
  277. if ($_GPC['type'] == 1) {
  278. $params['starttime'] = strtotime(date('Y-m-d'));
  279. $params['endtime'] = TIMESTAMP;
  280. } elseif ($_GPC['type'] == 2) {
  281. $params['starttime'] = strtotime('yesterday');
  282. $params['endtime'] = strtotime(date('Y-m-d'));
  283. }
  284. } else {
  285. $datelimit_start = $_GPC['datelimit']['start'];
  286. $datelimit_end = $_GPC['datelimit']['end'];
  287. $params['starttime'] = empty($datelimit_start) ? strtotime('-1 month') : strtotime($_GPC['datelimit']['start']);
  288. $params['endtime'] = empty($datelimit_end) ? TIMESTAMP : strtotime($_GPC['datelimit']['end']) + 86399;
  289. }
  290. $pindex = max(1, intval($_GPC['page']));
  291. $finance_info = cloud_flow_site_stat_day($params);
  292. foreach ($finance_info['items'] as &$val) {
  293. $val['extra_date'] = $val['year'] . '/' . $val['month'] . '/' . $val['day'];
  294. $val['search_date'] = $val['year'] . $val['month'] . $val['day'];
  295. $val['amount'] = $val['amount'] / 100;
  296. }
  297. $finance_items = $finance_info['items'];
  298. $pager = pagination($finance_info['total'], $pindex, $finance_info['size']);
  299. }
  300. if ($do == 'content_provider') {
  301. $iframe = cloud_auth_url('content-provider');
  302. $title = '广告主';
  303. }
  304. template('advertisement/content-provider');