123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- function store_goods_type_info($group = '') {
- $data = array(
- STORE_TYPE_MODULE => array('title' => '公众号应用', 'type' => STORE_TYPE_MODULE, 'sign' => ACCOUNT_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_WXAPP_MODULE => array('title' => '微信小程序应用', 'type' => STORE_TYPE_WXAPP_MODULE, 'sign' => WXAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_WEBAPP_MODULE => array('title' => 'PC应用', 'type' => STORE_TYPE_WEBAPP_MODULE, 'sign' => WEBAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_PHONEAPP_MODULE => array('title' => 'APP应用', 'type' => STORE_TYPE_PHONEAPP_MODULE, 'sign' => PHONEAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_XZAPP_MODULE => array('title' => '熊掌号应用', 'type' => STORE_TYPE_XZAPP_MODULE, 'sign' => XZAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_ALIAPP_MODULE => array('title' => '支付宝小程序应用', 'type' => STORE_TYPE_ALIAPP_MODULE, 'sign' => ALIAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_BAIDUAPP_MODULE => array('title' => '百度小程序应用', 'type' => STORE_TYPE_BAIDUAPP_MODULE, 'sign' => BAIDUAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_TOUTIAOAPP_MODULE => array('title' => '头条小程序应用', 'type' => STORE_TYPE_TOUTIAOAPP_MODULE, 'sign' => TOUTIAOAPP_TYPE_SIGN, 'group' => 'module'),
- STORE_TYPE_API => array('title' => '应用访问流量API', 'type' => STORE_TYPE_API, 'group' => ''),
- STORE_TYPE_PACKAGE => array('title' => '应用权限组', 'type' => STORE_TYPE_PACKAGE, 'group' => ''),
- STORE_TYPE_USER_PACKAGE => array('title' => '用户权限组', 'type' => STORE_TYPE_USER_PACKAGE, 'group' => ''),
- STORE_TYPE_ACCOUNT_PACKAGE => array('title' => '账号权限组', 'type' => STORE_TYPE_ACCOUNT_PACKAGE, 'group' => ''),
- STORE_TYPE_ACCOUNT => array('title' => '公众号平台', 'type' => STORE_TYPE_ACCOUNT, 'group' => 'account_num'),
- STORE_TYPE_WXAPP => array('title' => '微信小程序平台', 'type' => STORE_TYPE_WXAPP, 'group' => 'account_num'),
- STORE_TYPE_WEBAPP => array('title' => 'PC平台', 'type' => STORE_TYPE_WEBAPP, 'group' => 'account_num'),
- STORE_TYPE_PHONEAPP => array('title' => 'APP平台', 'type' => STORE_TYPE_PHONEAPP, 'group' => 'account_num'),
- STORE_TYPE_XZAPP => array('title' => '熊掌号平台', 'type' => STORE_TYPE_XZAPP, 'group' => 'account_num'),
- STORE_TYPE_ALIAPP => array('title' => '支付宝小程序平台', 'type' => STORE_TYPE_ALIAPP, 'group' => 'account_num'),
- STORE_TYPE_BAIDUAPP => array('title' => '百度小程序平台', 'type' => STORE_TYPE_BAIDUAPP, 'group' => 'account_num'),
- STORE_TYPE_TOUTIAOAPP => array('title' => '头条小程序平台', 'type' => STORE_TYPE_TOUTIAOAPP, 'group' => 'account_num'),
- STORE_TYPE_ACCOUNT_RENEW => array('title' => '公众号', 'type' => STORE_TYPE_ACCOUNT_RENEW, 'group' => 'renew'),
- STORE_TYPE_WXAPP_RENEW => array('title' => '微信小程序', 'type' => STORE_TYPE_WXAPP_RENEW, 'group' => 'renew'),
- STORE_TYPE_WEBAPP_RENEW => array('title' => 'PC', 'type' => STORE_TYPE_WEBAPP_RENEW, 'group' => 'renew'),
- STORE_TYPE_PHONEAPP_RENEW => array('title' => 'APP', 'type' => STORE_TYPE_PHONEAPP_RENEW, 'group' => 'renew'),
- STORE_TYPE_XZAPP_RENEW => array('title' => '熊掌号', 'type' => STORE_TYPE_XZAPP_RENEW, 'group' => 'renew'),
- STORE_TYPE_ALIAPP_RENEW => array('title' => '支付宝小程序', 'type' => STORE_TYPE_ALIAPP_RENEW, 'group' => 'renew'),
- STORE_TYPE_BAIDUAPP_RENEW => array('title' => '百度小程序', 'type' => STORE_TYPE_BAIDUAPP_RENEW, 'group' => 'renew'),
- STORE_TYPE_TOUTIAOAPP_RENEW => array('title' => '头条小程序', 'type' => STORE_TYPE_TOUTIAOAPP_RENEW, 'group' => 'renew'),
- );
- if (!empty($group)) {
- foreach ($data as $k => $item) {
- if ($item['group'] != $group) {
- unset($data[$k]);
- }
- }
- } else {
- foreach ($data as $k => $item) {
- if (!empty($item['group'])) {
- $data[$item['group']][$item['type']] = $item;
- }
- }
- }
- return $data;
- }
- function store_goods_info($id) {
- $result = array();
- $id = intval($id);
- if (empty($id)) {
- return $result;
- }
- $result = table('store')->goodsInfo($id);
- if (!empty($result[$id])) {
- $result = $result[$id];
- }
- return $result;
- }
- function store_goods_changestatus($id) {
- $result = false;
- $id = intval($id);
- if (empty($id)) {
- return $result;
- }
- $if_exist = pdo_get('site_store_goods', array('id' => $id));
- if (!empty($if_exist)) {
- $status = $if_exist['status'] == 1 ? 0 : 1;
- $data = array('status' => $status);
- $result = pdo_update('site_store_goods', $data, array('id' => $id));
- }
- return $result;
- }
- function store_goods_delete($id) {
- $result = false;
- $id = intval($id);
- if (empty($id)) {
- return $result;
- }
- $result = pdo_update('site_store_goods', array('status' => 2), array('id' => $id));
- return $result;
- }
- function update_wish_goods_info($update_data, $module_name) {
- if (!empty($update_data['title'])) {
- $data['title'] = $update_data['title'];
- $data['title_initial'] = $update_data['title_initial'];
- }
- if (!empty($update_data['logo'])) {
- $data['logo'] = $update_data['logo'];
- }
- $store_goods_exists = pdo_get('site_store_goods', array('module' => $module_name));
- $store_goods_cloud_exists = pdo_get('site_store_goods_cloud', array('name' => $module_name));
- $module_exists = pdo_get('modules', array('name' => $module_name));
- if ($store_goods_exists) {
- pdo_update('site_store_goods', $data, array('module' => $module_name));
- }
- if ($module_exists) {
- pdo_update('modules', $data, array('name' => $module_name));
- }
- if ($store_goods_cloud_exists) {
- unset($data['title_initial']);
- pdo_update('site_store_goods_cloud', $data, array('name' => $module_name));
- }
- cache_build_module_info($module_name);
- return true;
- }
- function store_goods_post($data) {
- $result = false;
- if (empty($data)) {
- return $result;
- }
- $post = array();
- if (!empty($data['title'])) {
- $post['title'] = trim($data['title']);
- }
- if (is_numeric($data['price'])) {
- $post['price'] = $data['price'];
- }
- $post['slide'] = $data['slide'];
- if (!empty($data['status'])) {
- $post['status'] = 1;
- }
- if (!empty($data['ability']) || !empty($data['synopsis'])) {
- $post['synopsis'] = empty($data['ability']) ? trim($data['synopsis']) : trim($data['ability']);
- }
- if (!empty($data['description'])) {
- $post['description'] = trim($data['description']);
- }
- if (!empty($data['api_num'])) {
- $post['api_num'] = intval($data['api_num']);
- }
- if (!empty($data['unit'])) {
- $post['unit'] = $data['unit'];
- } else {
- if ($data['type'] != STORE_TYPE_API) {
- $post['unit'] = 'month';
- }
- }
- $post['account_num'] = $data['account_num'];
- $post['wxapp_num'] = $data['wxapp_num'];
- $post['platform_num'] = $data['platform_num'] == 0 ? 1 : $data['platform_num'];
- $post['module_group'] = $data['module_group'];
- $post['user_group'] = $data['user_group'];
- $post['account_group'] = $data['account_group'];
- $post['user_group_price'] = $data['user_group_price'];
- if ($data['type'] == STORE_TYPE_ACCOUNT_RENEW) {
- $post['account_num'] = $data['account_num'] == 0 ? 1 : $data['account_num'];
- }
- if ($data['type'] == STORE_TYPE_WXAPP_RENEW) {
- $post['wxapp_num'] = $data['wxapp_num'] == 0 ? 1 : $data['wxapp_num'];
- }
- if (!empty($data['id'])) {
- $result = pdo_update('site_store_goods', $post, array('id' => $data['id']));
- if (!empty($data['module'])) {
- $update_data = array('title' => $post['title'], 'title_initial' => get_first_pinyin($post['title']), 'logo' => $data['logo']);
- $result = update_wish_goods_info($update_data, $data['module']);
- }
- } else {
- $post['type'] = $data['type'];
- $post['createtime'] = TIMESTAMP;
- $post['title_initial'] = get_first_pinyin($data['title']);
- if (empty($post['unit'])) {
- $post['unit'] = 'month';
- }
- if ($data['type'] == STORE_TYPE_API) {
- $post['unit'] = 'ten_thousand';
- }
- $post['module'] = trim($data['module']);
- $result = pdo_insert('site_store_goods', $post);
- }
- return $result;
- }
- function store_order_info($id) {
- $result = array();
- $id = intval($id);
- if (empty($id)) {
- return $result;
- }
- $store_table = table('store');
- $result = $store_table->searchOrderInfo($id);
- if (!empty($result[$id])) {
- $result = $result[$id];
- }
- return $result;
- }
- function store_order_change_price($id, $price) {
- global $_W;
- $result = false;
- $id = intval($id);
- $price = floatval($price);
- $if_exist = store_order_info($id);
- if (empty($id) || empty($if_exist)) {
- return $result;
- }
- if (user_is_vice_founder() || empty($_W['isfounder'])) {
- return $result;
- }
- pdo_update('core_paylog', array('card_fee' => $price), array('module' => 'store', 'tid' => $id));
- $result = pdo_update('site_store_order', array('amount' => $price, 'changeprice' => 1), array('id' => $id));
- return $result;
- }
- function store_order_delete($id) {
- $result = false;
- $id = intval($id);
- if (empty($id)) {
- return $result;
- }
- $result = pdo_update('site_store_order', array('type' => STORE_ORDER_DELETE), array('id' => $id));
- return $result;
- }
- function store_add_cash_order($orderid) {
- global $_W;
- $store_setting = $_W['setting']['store'];
- if (empty($store_setting['cash_status']) || empty($store_setting['cash_ratio'])) {
- return error(1, '未开启分销, 或者提成比例为0');
- }
- $order = store_order_info($orderid);
- if (empty($order)) {
- return error(1, '订单不存在');
- }
- if ($order['type'] != STORE_ORDER_FINISH) {
- return error(1, '订单未支付');
- }
- if ($order['amount'] <= 0) {
- return error(1, '订单金额为0');
- }
- $order_cash = pdo_get('site_store_cash_order', array('order_id' => $order['id']));
- if (!empty($order_cash)) {
- return error(1, '分销订单已存在');
- }
- $user_founder = table('users_founder_own_users')->getFounderByUid($order['buyerid']);
- if (empty($user_founder['founder_uid'])) {
- return error(1, '上级用户非副创始人');
- }
- pdo_insert('site_store_cash_order', array(
- 'number' => date('YmdHis') . random(6, 1),
- 'founder_uid' => $user_founder['founder_uid'],
- 'order_id' => $order['id'],
- 'goods_id' => $order['goodsid'],
- 'order_amount' => $order['amount'],
- 'create_time' => TIMESTAMP,
- 'status' => 1,
- ));
- if (pdo_insertid()) {
- return true;
- } else {
- return error(1, '写入数据失败');
- }
- }
- function store_get_cash_orders($condition = array(), $page = 1, $psize = 15) {
- global $_W;
- $cash_orders = pdo_getall('site_store_cash_order', $condition, array(), '', 'id DESC', ($page - 1) * $psize . ',' . $psize);
- if (empty($cash_orders)) {
- return array('list' => array(), 'total' => 0);
- }
- $total = pdo_getcolumn('site_store_cash_order', $condition, 'count(*)');
- $goods_ids = $order_ids = array();
- if (empty($_W['setting']['store']['cash_status']) || empty($_W['setting']['store']['cash_ratio'])) {
- $cash_ratio = 0;
- } else {
- $cash_ratio = $_W['setting']['store']['cash_ratio'];
- }
- foreach ($cash_orders as $k => $order) {
- $goods_ids[] = $order['goods_id'];
- $order_ids[] = $order['order_id'];
- $cash_orders[$k]['cash_amount'] = sprintf('%.2f', $order['order_amount'] * $cash_ratio / 100);
- }
- $store_table = table('store');
- $goods = $store_table->goodsInfo($goods_ids);
- $orders = $store_table->searchOrderInfo($order_ids);
- foreach ($cash_orders as $k => $order) {
- $cash_orders[$k]['order'] = empty($orders[$order['order_id']]) ? array() : $orders[$order['order_id']];
- if (empty($goods[$order['goods_id']])) {
- $cash_orders[$k]['goods'] = array();
- } else {
- if (in_array($goods[$order['goods_id']]['type'], array(STORE_TYPE_MODULE, STORE_TYPE_WXAPP_MODULE))) {
- $cash_orders[$k]['goods'] = module_fetch($goods[$order['goods_id']]['module']);
- $cash_orders[$k]['goods']['type'] = $goods[$order['goods_id']]['type'];
- } else {
- $cash_orders[$k]['goods'] = $goods[$order['goods_id']];
- }
- }
- }
- return array(
- 'list' => $cash_orders,
- 'total' => $total
- );
- }
- function store_get_founder_can_cash_amount($founder_id, $has_refuse = false) {
- global $_W;
- $store_setting = $_W['setting']['store'];
- if (empty($store_setting['cash_status']) || empty($store_setting['cash_ratio'])) {
- return 0;
- }
- $status = empty($has_refuse) ? 1 : array(1, 3);
- $can_cash_amount = pdo_getcolumn('site_store_cash_order', array('founder_uid' => $founder_id, 'status' => $status), 'sum(order_amount)');
- return sprintf('%.2f', floatval($can_cash_amount) * $store_setting['cash_ratio'] / 100);
- }
- function store_add_cash_log($founder_id) {
- $can_cash_amount = store_get_founder_can_cash_amount($founder_id);
- if ($can_cash_amount <= 0) {
- return error(1, '暂无待提现订单');
- }
- pdo_insert('site_store_cash_log', array(
- 'number' => date('YmdHis') . random(6, 1),
- 'founder_uid' => $founder_id,
- 'amount' => $can_cash_amount,
- 'create_time' => TIMESTAMP,
- 'status' => 1,
- ));
- $cash_log_id = pdo_insertid();
- if (empty($cash_log_id)) {
- return error(1, '操作失败, 请重试');
- }
- pdo_update(
- 'site_store_cash_order',
- array('status' => 2, 'cash_log_id' => $cash_log_id),
- array('founder_uid' => $founder_id, 'status' => 1)
- );
- return true;
- }
- function store_get_cash_logs($condition = array(), $page = 1, $psize = 15) {
- $cash_logs = pdo_getall('site_store_cash_log', $condition, array(), '', 'id DESC', ($page - 1) * $psize . ',' . $psize);
- if (empty($cash_logs)) {
- return array('list' => array(), 'total' => 0);
- }
- $founder_uids = array();
- foreach ($cash_logs as $log) {
- $founder_uids[] = $log['founder_uid'];
- }
- $users_info = table('users')->where('uid', $founder_uids)->getall('uid');
- foreach ($cash_logs as $k => $log) {
- $cash_logs[$k]['username'] = empty($users_info[$log['founder_uid']]['username']) ? '' : $users_info[$log['founder_uid']]['username'];
- }
- $total = pdo_getcolumn('site_store_cash_log', $condition, 'count(*)');
- return array(
- 'list' => $cash_logs,
- 'total' => $total
- );
- }
|