Manage.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function relation_api()
  7. {
  8. $admin = Dever::load('manage/auth.data');
  9. print_r($admin);die;
  10. if ($admin['role']['id'] != 1) {
  11. Dever::alert('无法访问');
  12. }
  13. $data = array();
  14. $data['mobile'] = Dever::input('mobile');
  15. $member = Dever::db('agent/member')->find(array('mobile' => $data['mobile']));
  16. $data['mid'] = $member['id'];
  17. // Dever::input('mid');
  18. $data['link'] = Dever::decode(Dever::input('refer'));
  19. return Dever::render('index', $data);
  20. }
  21. # 后台设置区域
  22. public function updateArea($id, $name, $data)
  23. {
  24. Dever::config('base')->hook = true;
  25. $id = $id['where_id'];
  26. $area = Dever::param('area', $data);#修改后
  27. $role = Dever::param('role', $data);
  28. $level_id = Dever::param('level_id', $data);
  29. $member = Dever::db('agent/member')->find($id);
  30. if (!$member) {
  31. return;
  32. }
  33. if ($area && is_array($area) && $role) {
  34. $role = Dever::db('setting/role')->find($role);
  35. $area_string = array();
  36. if ($role && $role['type'] == 2) {
  37. $area_string = Dever::load('agent/lib/order')->checkArea($area, $role, $member['id']);
  38. } else {
  39. $area_string = implode(',', $area);
  40. $area_string = str_replace(',-1', '', $area_string);
  41. }
  42. $data['set_area'] = $area_string;
  43. $this->upLog($member, $role, $area_string, -1, 3);
  44. }
  45. if ($level_id && $level_id != $member['level_id']) {
  46. $group_num = Dever::load('invite/api')->getChildNum($member['id'], 1);
  47. Dever::load('agent/lib/level_log')->up($member['id'], -1, $member['level_id'], $level_id, 0, 0, $group_num);
  48. }
  49. return $data;
  50. }
  51. # 更改日志
  52. private function upLog($member, $role, $area, $order_id = -1, $type = 3)
  53. {
  54. if (is_numeric($role)) {
  55. $role = Dever::db('setting/role')->find($role);
  56. }
  57. if (!$role) {
  58. return;
  59. }
  60. $this->upRole($member, $role, $area, $order_id);
  61. $this->upArea($member, $role, $area, $order_id, $type);
  62. }
  63. private function upRole($member, $role, $area, $order_id = -1)
  64. {
  65. if ($role['id'] == $member['role']) {
  66. return;
  67. }
  68. $data['mid'] = $member['id'];
  69. $data['order_id'] = $order_id;
  70. $data['old_role'] = $member['role'];
  71. $data['new_role'] = $role['id'];
  72. $data['area'] = $area;
  73. if ($order_id && $order_id > 0) {
  74. $data['type'] = 1;
  75. $order = Dever::db('agent/order')->find($order_id);
  76. $data['price'] = $order['price'];
  77. } else {
  78. $data['type'] = 2;
  79. $admin = Dever::load('manage/auth.info');
  80. $data['audit_admin'] = $admin['id'];
  81. }
  82. Dever::db('agent/member_account_log')->insert($data);
  83. }
  84. private function upArea($member, $role, $area, $order_id = -1, $type = 3)
  85. {
  86. if (!$role) {
  87. return;
  88. }
  89. if ($area == $member['area']) {
  90. return;
  91. }
  92. $area_data = array('mid' => $member['id']);
  93. $area_info = Dever::db('agent/member_area')->getOne($area_data);
  94. if ($area_info) {
  95. Dever::db('agent/member_area')->update(array('where_id' => $area_info['id'], 'state' => 2));
  96. }
  97. if ($role && $role['type'] == 2) {
  98. Dever::load('area/api')->upStatus($area, 2);
  99. $area_data['order_id'] = $order_id;
  100. $area_data['role'] = $role['id'];
  101. $area_data['area'] = $area;
  102. $area_data['type'] = $type;
  103. $area_data['price'] = 0;
  104. $area_data['status'] = 1;
  105. Dever::db('agent/member_area')->insert($area_data);
  106. }
  107. $this->area_log($member['id'], $order_id, $member['area'], $area);
  108. }
  109. # 获取
  110. # 设置上级
  111. public function setParent_commit($id, $name, $data)
  112. {
  113. //Dever::alert('暂未开放');
  114. Dever::config('base')->hook = true;
  115. $mid = Dever::param('mid', $data);
  116. $parent_mobile = trim(Dever::param('parent_mobile', $data));
  117. if ($mid && $parent_mobile) {
  118. $member = Dever::db('agent/member')->find($mid);
  119. $parent = Dever::db('agent/member')->find(array('mobile' => $parent_mobile));
  120. if ($parent && $parent['status'] == 2) {
  121. if ($member['parent_mid'] == $parent['id']) {
  122. Dever::alert('上级代理商设置失败');
  123. return;
  124. }
  125. if ($member['parent_mid'] == $mid) {
  126. Dever::alert('上级代理商不能设置为自己');
  127. return;
  128. }
  129. # 重置关系
  130. Dever::load('invite/api')->resetRelation($mid, $parent['id']);
  131. /*
  132. # 删除之前关系
  133. Dever::load('invite/api')->dropRelation($mid, $parent['id']);
  134. # 获取所有下级
  135. $child = Dever::load('invite/api')->getChild($mid);
  136. if ($child) {
  137. foreach ($child as $k => $v) {
  138. Dever::load('invite/api')->dropRelation($v['to_uid'], $parent['id']);
  139. }
  140. }
  141. # 重新设置关系
  142. Dever::load('invite/api')->setRelation($mid, $parent['id']);
  143. */
  144. Dever::db('agent/member')->update(array('id' => $mid, 'parent_mid' => $parent['id']));
  145. } else {
  146. Dever::alert('上级代理商还未注册或者已封禁');
  147. }
  148. }
  149. }
  150. public function orderUpdateParent($id, $name, $data)
  151. {
  152. Dever::config('base')->hook = true;
  153. $invite_type = Dever::param('invite_type', $data);
  154. $parent_code = Dever::param('parent_code', $data);
  155. if ($invite_type == 1 && $parent_code) {
  156. $parent_mid = Dever::load('invite/api')->getUid($parent_code);
  157. if ($parent_mid) {
  158. $member = Dever::db('agent/member')->find($parent_mid);
  159. if (!$member) {
  160. Dever::alert('错误的邀请码');
  161. }
  162. $order = Dever::db('agent/order')->find($id['where_id']);
  163. if ($order['mid'] == $member['id']) {
  164. Dever::alert('邀请人不能是自己');
  165. }
  166. $data['set_parent_mid'] = $parent_mid;
  167. return $data;
  168. } else {
  169. Dever::alert('错误的邀请码');
  170. }
  171. }
  172. }
  173. public function orderStartUpdate($id, $name, $data)
  174. {
  175. $order_id = Dever::param('order_id', $data);
  176. if ($order_id) {
  177. $order = Dever::db('agent/order')->find($order_id);
  178. if ($order && $order['source_id'] < 0) {
  179. if ($order['parent_mid'] > 0) {
  180. $member = Dever::db('agent/member')->find($order['parent_mid']);
  181. if ($member['status'] == 2) {
  182. return $data;
  183. }
  184. }
  185. Dever::alert('直属上级未认证,无法进行初审');
  186. }
  187. }
  188. }
  189. public function orderUpdate($id, $name, $data)
  190. {
  191. Dever::config('base')->hook = true;
  192. $audit = Dever::param('audit', $data);
  193. $status = Dever::param('status', $data);
  194. $desc = Dever::param('desc', $data);
  195. $order_id = Dever::param('order_id', $data);
  196. $order = Dever::db('agent/order')->find($order_id);
  197. if ($order_id && $order && $status) {
  198. if ($status < 3) {
  199. if ($audit == 1) {
  200. $update = array('where_id' => $order_id, 'status' => $status+1);
  201. if ($status == 1) {
  202. $soft_price = Dever::param('soft_price', $data);
  203. $price = Dever::param('price', $data);
  204. $prize_type = Dever::param('prize_type', $data);
  205. $option_price = Dever::param('option_price', $data);
  206. if ($prize_type == 2) {
  207. # 扣减已有名额,判断一下
  208. $prize = Dever::db('setting/prize')->find(array('type' => 1, 'price' => $order['price']));
  209. if ($prize) {
  210. $member_goods = Dever::db('agent/member_goods')->getOne(array('mid' => $order['mid'], 'type' => 3, 'type_id' => $prize['id']));
  211. if ($member_goods && $member_goods['num'] > 0) {
  212. # 有名额
  213. $price = 0;
  214. # 开始扣减
  215. $member = Dever::db('agent/member')->find($order['mid']);
  216. Dever::load('agent/lib/dhorder')->action($member, $prize['name'], $prize['num'], $prize['price'], array(), -1, 2, 3, $prize['id'], $desc);
  217. }
  218. }
  219. }
  220. if ($price <= 0) {
  221. $update['get_type'] = 2;
  222. } else {
  223. $update['get_type'] = 1;
  224. }
  225. $update['price'] = $price;
  226. $update['agent_cash'] = $price;
  227. $update['soft_cash'] = 0;
  228. $update['option_price']=$option_price;
  229. $cstatus = Dever::param('cstatus', $data);
  230. if ($cstatus && $cstatus == 2 && $price > 0) {
  231. # 拆分代理费
  232. if ($soft_price > 0) {
  233. $update['agent_cash'] = $price - $soft_price;
  234. $update['soft_cash'] = $soft_price;
  235. } else {
  236. $role = Dever::db('setting/role')->one($order['role']);
  237. if ($role && $role['soft']) {
  238. if (strstr($role['soft'], '%')) {
  239. $role['soft'] = str_replace('%', '', $role['soft']);
  240. $role['soft'] = $price * ($role['soft']/100);
  241. }
  242. $update['agent_cash'] = $price - $role['soft'];
  243. $update['soft_cash'] = $role['soft'];
  244. }
  245. }
  246. }
  247. # 增加业绩
  248. //Dever::load('bill/lib/sell')->up($order['mid'], 2, $order['price'], $order['role'], $order['id'], $order['name'] . '成为代理商');
  249. } elseif ($status == 2) {
  250. if ($order['mid'] && $order['mid'] > 0 && $order['parent_mid'] && $order['parent_mid'] > 0) {
  251. Dever::load('invite/api')->setRelation($order['mid'], $order['parent_mid']);
  252. }
  253. $update['pay_status'] = 2;
  254. Dever::load('agent/lib/member')->create($order);
  255. }
  256. Dever::db('agent/order')->update($update);
  257. } else {
  258. Dever::db('agent/order')->update(array('where_id' => $order_id, 'status' => 5, 'history_status' => $order['status'], 'audit_desc' => $desc));
  259. if (Dever::project('sms')) {
  260. Dever::load('sms/api')->send('daili_reg_no', $order['mobile'], array('name' => $order['name'], 'content' => $desc));
  261. }
  262. }
  263. } elseif ($status == 3) {
  264. $info = Dever::db('agent/order_process')->find(array('id' => $id, 'clear' => true));
  265. if ($info && $info['status'] == 3) {
  266. $info['type'] = explode(',', $info['type']);
  267. }
  268. if (in_array(2, $info['type'])) {
  269. $goods_status = 3;
  270. } else {
  271. $goods_status = 2;
  272. }
  273. Dever::db('agent/order')->update(array('where_id' => $order_id, 'fdate' => time(), 'status' => 4, 'goods_status' => $goods_status));
  274. # 通知短信
  275. if (Dever::project('sms')) {
  276. $order = Dever::db('agent/order')->find($order_id);
  277. Dever::load('sms/api')->send('daili_reg_yes', $order['mobile'], array('name' => $order['name']));
  278. }
  279. $order = Dever::db('agent/order')->find($order_id);
  280. if ($order && $order['mid']) {
  281. $member = Dever::db('agent/member')->find($order['mid']);
  282. $update['where_id'] = $order['mid'];
  283. if ($member && $member['status'] == 1) {
  284. $update['status'] = 2;
  285. $update['rdate'] = time();
  286. }
  287. $update['area'] = $order['area'];
  288. $update['role'] = $order['role'];
  289. Dever::db('agent/member')->update($update);
  290. if ($order['price'] > 0) {
  291. $type = 1;
  292. } else {
  293. $type = 2;
  294. }
  295. $this->upLog($member, $order['role'], $order['area'], $order['id'], $type);
  296. }
  297. }
  298. }
  299. }
  300. #区域日志
  301. public function area_log($mid,$order_id,$old_area, $area) {
  302. $data['mid']=$mid;
  303. $data['order_id']=$order_id;
  304. $data['old_area']=$old_area;
  305. $data['area']=$area;
  306. if ($order_id && $order_id > 0) {
  307. $data['type'] = 1;
  308. } else {
  309. $admin = Dever::load('manage/auth.info');
  310. $data['audit_admin'] = $admin['id'];
  311. $data['type'] = 2;
  312. }
  313. $ids=Dever::db('agent/member_area_log')->insert($data);
  314. return $ids;
  315. }
  316. # 发放权益
  317. public function set_commit_api()
  318. {
  319. Dever::config('base')->hook = true;
  320. $type = Dever::input('type', 2);
  321. $order_id = Dever::input('order_id');
  322. # 检测是否发放过了
  323. $order = Dever::db('agent/order')->find($order_id);
  324. if ($order['status'] != 3) {
  325. //Dever::alert('无发放权限');
  326. }
  327. $order_process = Dever::db('agent/order_process')->find(array('order_id' => $order_id, 'status' => 3));
  328. $yes = -1;
  329. if (!$order_process) {
  330. # 可以发放
  331. $yes = 1;
  332. } elseif ($order_process) {
  333. $order_process['type'] = explode(',', $order_process['type']);
  334. if (!in_array($type, $order_process['type'])) {
  335. # 可以发放
  336. $yes = 2;
  337. }
  338. }
  339. if ($yes > 0) {
  340. if ($yes == 1) {
  341. $data['order_id'] = $order_id;
  342. $data['status'] = 3;
  343. $data['type'] = '1,' . $type;
  344. $state = Dever::db('agent/order_process')->insert($data);
  345. } else {
  346. $data['where_id'] = $order_process['id'];
  347. $order_process['type'][] = $type;
  348. $data['type'] = implode(',', $order_process['type']);
  349. $state = Dever::db('agent/order_process')->update($data);
  350. }
  351. if ($state) {
  352. if ($type == 2) {
  353. $this->setGoods($order);
  354. } elseif ($type == 3) {
  355. $this->setCash($order);
  356. } elseif ($type == 5) {
  357. $this->setAgreement($order);
  358. }
  359. }
  360. return 'reload';
  361. } else {
  362. Dever::alert('无发放权限');
  363. }
  364. }
  365. # 设置多个权益
  366. private function setGoods($order)
  367. {
  368. $t = 1;
  369. $goods = Dever::db('agent/order_goods')->getData(array('order_id' => $order['id']));
  370. if (!$goods) {
  371. $goods = Dever::db('setting/role_goods')->getData(array('role_id' => $order['role'], 'give' => $order['order_type']));
  372. $t = intval($order['agent_cash']/10000);
  373. if ($t <= 0) {
  374. $t = 1;
  375. }
  376. }
  377. if ($goods) {
  378. $where = array();
  379. $goods_cash = 0;
  380. foreach ($goods as $k => $v) {
  381. $price = $this->addGoods($order, $v, $t);
  382. if ($price && $v['type'] < 3) {
  383. # 计算商品价值
  384. $goods_cash += $price;
  385. }
  386. }
  387. $update = array();
  388. if ($goods_cash) {
  389. $update['goods_cash'] = $goods_cash;
  390. }
  391. $update['goods_status'] = 3;
  392. $update['where_id'] = $order['id'];
  393. Dever::db('agent/order')->update($update);
  394. }
  395. }
  396. # 新增权益
  397. private function addGoods($order, $v, $t)
  398. {
  399. $cash = $price = 0;
  400. if ($v['type'] == 1) {
  401. $v['num'] = $v['num'] * $t;
  402. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['type_id'], $v['sku_id']);
  403. $price = $goods_info['price'];
  404. $cash = $goods_info['price'] * $v['num'];
  405. if (isset($goods_info['sku'])) {
  406. $sku = '-' . $goods_info['sku']['string'];
  407. } else {
  408. $sku = '';
  409. }
  410. $name = $goods_info['name'] . $sku;
  411. } elseif ($v['type'] == 2) {
  412. $v['sku_id'] = -1;
  413. # 生成一个电子券
  414. $card = Dever::db('card/info')->find($v['type_id']);
  415. if (!$card) {
  416. return false;
  417. }
  418. $name = $card['name'];
  419. if ($card['create_type'] == 2) {
  420. $cash = $card['price']*$v['num'] * $t;
  421. $price = $cash;
  422. $v['num'] = 1;
  423. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  424. if (!$v['sku_id']) {
  425. return false;
  426. }
  427. } else {
  428. $cash = $card['price'];
  429. $price = $cash;
  430. $total = $t*$v['num'];
  431. $t = 1;
  432. for($i=0; $i<$total;$i++) {
  433. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  434. if ($v['sku_id']) {
  435. $where['mid'] = $order['mid'];
  436. $where['type'] = $v['type'];
  437. $where['type_id'] = $v['type_id'];
  438. $where['sku_id'] = $v['sku_id'];
  439. $info = Dever::db('agent/member_goods')->find($where);
  440. if (!$info) {
  441. $up = $where;
  442. $up['total_num'] = $t;
  443. $up['cash'] = $cash;
  444. $up['price'] = $price;
  445. $up['name'] = $name;
  446. $state = Dever::db('agent/member_goods')->insert($up);
  447. if ($state) {
  448. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $t, 0, $t, $name);
  449. }
  450. }
  451. }
  452. }
  453. return;
  454. }
  455. } elseif ($v['type'] == 3) {
  456. $prize = Dever::db('setting/prize')->find($v['type_id']);
  457. $price = $prize['price'];
  458. $cash = $prize['price']*$v['num'];
  459. $name = $prize['name'];
  460. }
  461. $where['mid'] = $order['mid'];
  462. $where['type'] = $v['type'];
  463. $where['type_id'] = $v['type_id'];
  464. $where['sku_id'] = $v['sku_id'];
  465. $info = Dever::db('agent/member_goods')->find($where);
  466. if ($info) {
  467. $up['where_id'] = $info['id'];
  468. $up['total_num'] = $info['total_num'] + $v['num'];
  469. $up['cash'] = $cash;
  470. $up['price'] = $price;
  471. $up['name'] = $name;
  472. $state = Dever::db('agent/member_goods')->update($up);
  473. if ($state) {
  474. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $v['num'], $info['total_num'], $up['total_num'], $name);
  475. }
  476. } else {
  477. $up = $where;
  478. $up['total_num'] = $v['num'];
  479. $up['cash'] = $cash;
  480. $up['price'] = $price;
  481. $up['name'] = $name;
  482. $state = Dever::db('agent/member_goods')->insert($up);
  483. if ($state) {
  484. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $v['num'], 0, $up['total_num'], $name);
  485. }
  486. }
  487. return $cash;
  488. }
  489. private function setCash($order)
  490. {
  491. $param = Dever::input('param');
  492. if ($param) {
  493. $param = explode(',', $param);
  494. foreach ($param as $k => $v) {
  495. $t = Dever::array_decode($v);
  496. $where['type'] = $t['type'];
  497. $where['order_id'] = $order['id'];
  498. $where['mid'] = $order['mid'];
  499. $where['parent_mid'] = $t['parent_mid'];
  500. $info = Dever::db('agent/order_cash')->find($where);
  501. if (!$info) {
  502. $insert = $where;
  503. $insert['cash'] = $t['cash'];
  504. $insert['per'] = $t['per'];
  505. if (isset($t['prize_id'])) {
  506. $insert['prize_id'] = $t['prize_id'];
  507. }
  508. Dever::db('agent/order_cash')->insert($insert);
  509. } else {
  510. $update['where_id'] = $info['id'];
  511. $update['cash'] = $t['cash'];
  512. $update['per'] = $t['per'];
  513. if (isset($t['prize_id'])) {
  514. $update['prize_id'] = $t['prize_id'];
  515. }
  516. Dever::db('agent/order_cash')->update($update);
  517. }
  518. if (isset($t['prize_id']) && isset($t['child_num'])) {
  519. $prize_info = Dever::db('setting/prize')->find($t['prize_id']);
  520. if ($prize_info) {
  521. $prize_insert['order_id'] = $order['order_id'];
  522. $prize_insert['mid'] = $t['parent_mid'];
  523. $prize_insert['child_num'] = $t['child_num'];
  524. $prize_insert['prize_id'] = $prize_info['id'];
  525. Dever::db('agent/member_prize')->insert($prize_insert);
  526. $prize['type'] = 3;
  527. $prize['type_id'] = $prize_info['id'];
  528. $prize['sku_id'] = -1;
  529. $prize['num'] = $prize_info['num'];
  530. $this->addGoods($order, $prize);
  531. }
  532. }
  533. if (isset($t['parent_goods_id'])) {
  534. $parent_goods = Dever::db('agent/member_goods')->getOne(array('id' => $t['parent_goods_id']));
  535. if ($parent_goods && $parent_goods['num'] > 0) {
  536. $parent_prize = Dever::db('setting/prize')->find($parent_goods['type_id']);
  537. $member = Dever::db('agent/member')->find($t['parent_mid']);
  538. if ($member) {
  539. $desc = $parent_prize['name'] . '名额使用';
  540. Dever::load('agent/lib/dhorder')->action($member, $parent_prize['name'], $parent_prize['num'], $parent_prize['price'], array(), -1, 2, 3, $parent_goods['type_id'], $desc);
  541. }
  542. }
  543. }
  544. if (!isset($t['parent_level'])) {
  545. $t['parent_level'] = false;
  546. }
  547. if (!isset($t['child_num'])) {
  548. $t['child_num'] = 0;
  549. }
  550. $member = Dever::db('agent/member')->find($where['mid']);
  551. $desc = $member['name'] . '成为代理商,佣金'.$t['per'].'%';
  552. Dever::load('agent/lib/member')->up($where['parent_mid'], $order['id'], $order['role'], $where['type'], $t['cash'], $order['agent_cash'], $t['parent_level'], $desc, $t['child_num']);
  553. }
  554. }
  555. }
  556. private function setAgreement($order)
  557. {
  558. Dever::load('agent/lib/agreement')->up($order);
  559. }
  560. public function sellOrderUpdate($id, $name, $data)
  561. {
  562. Dever::config('base')->hook = true;
  563. $update = array();
  564. $audit = Dever::param('audit', $data);
  565. $desc = Dever::param('audit_desc', $data);
  566. $info = Dever::db('agent/dh_order')->one($id);
  567. if ($audit > 1 && $info && $info['status'] == 2) {
  568. if ($audit == 2) {
  569. # 成功
  570. Dever::setInput('order_id', $id);
  571. Dever::load('agent/lib/dhorder.audit_commit');
  572. } else {
  573. Dever::db('agent/dh_order')->update(array('where_id' => $id, 'status' => 7));
  574. Dever::load('agent/lib/dhorder')->updateSell($info, 2);
  575. if (Dever::project('sms')) {
  576. $member = Dever::db('agent/member')->find($info['mid']);
  577. Dever::load('sms/api')->send('daili_goods_no', $member['mobile'], array('name' => $member['name'], 'content' => $desc));
  578. }
  579. }
  580. }
  581. }
  582. # 确认收货
  583. public function setDhOrderStatus_api()
  584. {
  585. $order_id = Dever::input('order_id');
  586. $info = Dever::db('agent/dh_order')->find($order_id);
  587. if ($info) {
  588. Dever::load('agent/lib/dhorder')->finish($info, $info['shop_id']);
  589. return 'reload';
  590. } else {
  591. Dever::alert('错误的订单号');
  592. }
  593. }
  594. # 获取权益名称
  595. public function getGoods($type, $type_id, $sku_id)
  596. {
  597. if ($type == 1) {
  598. if ($sku_id == -2) {
  599. return '商品';
  600. }
  601. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($type_id, $sku_id);
  602. if (isset($goods_info['sku'])) {
  603. $sku = '-' . $goods_info['sku']['string'];
  604. } else {
  605. $sku = '';
  606. }
  607. return array('name' => $goods_info['name'] . $sku, 'price' => $goods_info['price']);
  608. } elseif ($type == 2) {
  609. $code = Dever::db('card/code')->find($sku_id);
  610. $card = Dever::db('card/info')->find($code['card_id']);
  611. return array('name' => $card['name'], 'price' => $code['total_cash']);
  612. } elseif ($type == 3) {
  613. $prize = Dever::db('setting/prize')->find($type_id);
  614. return array('name' => $prize['name'], 'price' => $prize['price']);
  615. }
  616. }
  617. public function setOrderStatus_api()
  618. {
  619. $where['where_id'] = Dever::input('id');
  620. $order = Dever::db('agent/order')->find($where['where_id']);
  621. if ($order) {
  622. $where['status'] = Dever::input('value');
  623. if ($where['status'] == 6) {
  624. $where['history_status'] = $order['status'];
  625. }
  626. Dever::db('agent/order')->update($where);
  627. }
  628. return 'reload';
  629. }
  630. public function upAgreement_api()
  631. {
  632. $id = Dever::input('id');
  633. if ($id) {
  634. Dever::load('agent/lib/agreement')->upContent($id);
  635. }
  636. return 'reload';
  637. }
  638. public function dropAgreement_api()
  639. {
  640. $id = Dever::input('id');
  641. if ($id) {
  642. Dever::load('agent/lib/agreement')->drop($id);
  643. }
  644. return 'reload';
  645. }
  646. }