HexiaoController.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author zcy
  12. *
  13. */
  14. namespace Home\Controller;
  15. /**
  16. * 核销员核销
  17. * Class HexiaoController
  18. * @package Home\Controller
  19. */
  20. class HexiaoController extends CommonController {
  21. protected function _initialize(){
  22. parent::_initialize();
  23. }
  24. /**
  25. * 核销员管理页面
  26. */
  27. public function hexiao_manage()
  28. {
  29. $_GPC = I('request.');
  30. $token = $_GPC['token'];
  31. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  32. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  33. {
  34. echo json_encode( array('code' => 1) );
  35. die();
  36. }
  37. $member_id = $weprogram_token['member_id'];
  38. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  39. if( $salesmember_id <= 0 )
  40. {
  41. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  42. die();
  43. }
  44. $data = array();
  45. //核销员门店信息
  46. $salesroom_list = D('Home/Salesroom')->get_salesrooms_by_smember_id($salesmember_id);
  47. $data['salesroom_list'] = $salesroom_list;
  48. //核销员今日核销记录
  49. $saleshexiao_record_list = D('Home/Salesroom')->get_today_hexiao_record_by_smember_id($salesmember_id);
  50. //核销员信息
  51. $salesroom_member = M('lionfish_comshop_salesroom_member')->where( array('id' => $salesmember_id) )->find();
  52. if(!empty($salesroom_member['last_salesroom_id'])){
  53. $salesroom = M('lionfish_comshop_salesroom')->where( array('id' => $salesroom_member['last_salesroom_id']) )->find();
  54. $salesroom_member['last_salesroom'] = $salesroom;
  55. }
  56. $data['salesroom_member'] = $salesroom_member;
  57. $data['saleshexiao_record_list'] = $saleshexiao_record_list;
  58. $data['today_saleshexiao_count'] = count($saleshexiao_record_list);
  59. echo json_encode( array('code' => 0, 'data' => $data) );
  60. }
  61. /**
  62. * 核销订单页面
  63. */
  64. public function hexiao_order_info(){
  65. $_GPC = I('request.');
  66. $token = $_GPC['token'];
  67. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  68. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  69. {
  70. echo json_encode( array('code' => 1) );
  71. die();
  72. }
  73. $member_id = $weprogram_token['member_id'];
  74. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  75. if( $salesmember_id <= 0 )
  76. {
  77. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  78. die();
  79. }
  80. $hexiao_volume_code = $_GPC['hexiao_volume_code'];
  81. if( empty($hexiao_volume_code) )
  82. {
  83. echo json_encode( array('code' => 3, 'msg' => '核销码不存在' ) );
  84. die();
  85. }
  86. $hexiao_info = D('Home/Salesroom')->get_hexiao_order_by_code($hexiao_volume_code,$salesmember_id);
  87. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $hexiao_info['orders']['order_id']) )->find();
  88. if($order_info['order_status_id'] == 5){
  89. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  90. die();
  91. }
  92. if($order_info['order_status_id'] == 3){
  93. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  94. die();
  95. }
  96. if($hexiao_info['is_exist'] == 0){
  97. echo json_encode( array('code' => 3, 'msg' => '请输入正确的手机号/券码' ) );
  98. die();
  99. }
  100. if($hexiao_info['is_exist'] == 2){
  101. echo json_encode( array('code' => 3, 'msg' => '核销员无核销权限' ) );
  102. die();
  103. }
  104. if($hexiao_info['is_exist'] == 4){
  105. echo json_encode( array('code' => 3, 'msg' => '该手机号无到店核销订单' ) );
  106. die();
  107. }
  108. echo json_encode( array('code' => 0, 'data' => $hexiao_info) );
  109. }
  110. /**
  111. * 核销整个订单
  112. */
  113. public function all_hx_order(){
  114. $_GPC = I('request.');
  115. $token = $_GPC['token'];
  116. $order_id = $_GPC['order_id'];
  117. $salesroom_id = $_GPC['salesroom_id'];
  118. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  119. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  120. {
  121. echo json_encode( array('code' => 1) );
  122. die();
  123. }
  124. $member_id = $weprogram_token['member_id'];
  125. if( empty($order_id) )
  126. {
  127. echo json_encode( array('code' => 3, 'msg' => '订单已全部核销,无法操作' ) );
  128. die();
  129. }
  130. $order_info = M('lionfish_comshop_order')->where( 'order_id in('.$order_id.')' )->select();
  131. if( empty($order_info) )
  132. {
  133. echo json_encode( array('code' => 3, 'msg' => '订单信息不存在' ) );
  134. die();
  135. }
  136. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  137. if( $salesmember_id <= 0 )
  138. {
  139. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  140. die();
  141. }
  142. $hx_order_count = 0 ;
  143. $oeders_hx_result = array();
  144. foreach($order_info as $var){
  145. if($var['order_status_id'] == 5){
  146. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  147. die();
  148. }
  149. if($var['order_status_id'] == 3){
  150. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  151. die();
  152. }
  153. if($var['order_status_id'] != 4){
  154. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  155. die();
  156. }
  157. $hx_result = D('Home/Salesroom')->hexiao_all_orders($var['order_id'],$salesmember_id,$salesroom_id);
  158. if($hx_result['hx_goods_count'] > 0){
  159. $hx_order_count += 1;
  160. }else{
  161. echo json_encode( array('code' => 3, 'msg' => '无核销商品') );
  162. }
  163. }
  164. if($hx_order_count > 0 ){
  165. $oeders_hx_result['hx_order_count'] = $hx_order_count;
  166. echo json_encode( array('code' => 0, 'data' => $oeders_hx_result) );
  167. }
  168. }
  169. /**
  170. * 核销商品(按订单核销的商品)
  171. */
  172. public function hx_order_goods(){
  173. $_GPC = I('request.');
  174. $token = $_GPC['token'];
  175. $hexiao_id = $_GPC['hexiao_id'];
  176. $salesroom_id = $_GPC['salesroom_id'];
  177. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  178. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  179. {
  180. echo json_encode( array('code' => 1) );
  181. die();
  182. }
  183. $member_id = $weprogram_token['member_id'];
  184. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  185. if( empty($saleshexiao_info) )
  186. {
  187. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  188. die();
  189. }
  190. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  191. if( $salesmember_id <= 0 )
  192. {
  193. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  194. die();
  195. }
  196. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $saleshexiao_info['order_id']) )->find();
  197. if($order_info['order_status_id'] == 5){
  198. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  199. die();
  200. }
  201. if($order_info['order_status_id'] == 3){
  202. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  203. die();
  204. }
  205. if($order_info['order_status_id'] != 4){
  206. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  207. die();
  208. }
  209. $hx_result = D('Home/Salesroom')->saleshexiao_order_goods($saleshexiao_info,$salesmember_id,$salesroom_id, 0);
  210. if($hx_result == 1){
  211. echo json_encode( array('code' => 0) );
  212. }else if($hx_result == 0){
  213. echo json_encode( array('code' => 3, 'msg' => '核销商品失败') );
  214. }else{
  215. echo json_encode( array('code' => 3, 'msg' => '无核销权限') );
  216. }
  217. }
  218. /**
  219. * 按次核销点击弹窗(按次核销商品)
  220. */
  221. public function get_hxgoods_bytimes(){
  222. $_GPC = I('request.');
  223. $token = $_GPC['token'];
  224. $hexiao_id = $_GPC['hexiao_id'];
  225. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  226. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  227. {
  228. echo json_encode( array('code' => 1) );
  229. die();
  230. }
  231. $member_id = $weprogram_token['member_id'];
  232. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  233. if( empty($saleshexiao_info) )
  234. {
  235. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  236. die();
  237. }
  238. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  239. if( $salesmember_id <= 0 )
  240. {
  241. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  242. die();
  243. }
  244. $hx_info = D('Home/Salesroom')->get_hxgoods_bytimes($saleshexiao_info,$salesmember_id);
  245. if($hx_info['status'] == -1){
  246. echo json_encode( array('code' => 3, 'msg' => '无核销权限' ) );
  247. die();
  248. }
  249. echo json_encode( array('code' => 0, 'data' => $hx_info) );
  250. }
  251. /**
  252. * 按次核销商品一次性核销完成
  253. */
  254. public function all_hx_order_goods_bytimes(){
  255. $_GPC = I('request.');
  256. $token = $_GPC['token'];
  257. //核销商品订单表id
  258. $hexiao_id = $_GPC['hexiao_id'];
  259. //门店id
  260. $salesroom_id = $_GPC['salesroom_id'];
  261. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  262. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  263. {
  264. echo json_encode( array('code' => 1) );
  265. die();
  266. }
  267. $member_id = $weprogram_token['member_id'];
  268. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  269. if( empty($saleshexiao_info) )
  270. {
  271. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  272. die();
  273. }
  274. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  275. if( $salesmember_id <= 0 )
  276. {
  277. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  278. die();
  279. }
  280. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $saleshexiao_info['order_id']) )->find();
  281. if($order_info['order_status_id'] == 5){
  282. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  283. die();
  284. }
  285. if($order_info['order_status_id'] == 3){
  286. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  287. die();
  288. }
  289. if($order_info['order_status_id'] != 4){
  290. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  291. die();
  292. }
  293. $hx_result = D('Home/Salesroom')->saleshexiao_order_goods($saleshexiao_info,$salesmember_id,$salesroom_id,0);
  294. if($hx_result == 1){
  295. echo json_encode( array('code' => 0) );
  296. }else if($hx_result == 0){
  297. echo json_encode( array('code' => 3, 'msg' => '核销商品失败') );
  298. }else{
  299. echo json_encode( array('code' => 3, 'msg' => '无核销权限') );
  300. }
  301. }
  302. /**
  303. * 核销商品(按次数核销的商品)
  304. */
  305. public function hx_order_goods_bytimes(){
  306. $_GPC = I('request.');
  307. $token = $_GPC['token'];
  308. //核销商品订单表id
  309. $hexiao_id = $_GPC['hexiao_id'];
  310. //门店id
  311. $salesroom_id = $_GPC['salesroom_id'];
  312. //核销次数
  313. $hx_times = $_GPC['hx_times'];
  314. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  315. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  316. {
  317. echo json_encode( array('code' => 1) );
  318. die();
  319. }
  320. if( empty($hx_times) || intval($hx_times) < 1 )
  321. {
  322. echo json_encode( array('code' => 3, 'msg' => '核销次数错误' ) );
  323. die();
  324. }
  325. $member_id = $weprogram_token['member_id'];
  326. $saleshexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hexiao_id) )->find();
  327. if( empty($saleshexiao_info) )
  328. {
  329. echo json_encode( array('code' => 3, 'msg' => '订单核销信息不存在' ) );
  330. die();
  331. }
  332. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  333. if( $salesmember_id <= 0 )
  334. {
  335. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  336. die();
  337. }
  338. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $saleshexiao_info['order_id']) )->find();
  339. if($order_info['order_status_id'] == 5){
  340. echo json_encode( array('code' => 3, 'msg' => '订单已取消,无法核销' ) );
  341. die();
  342. }
  343. if($order_info['order_status_id'] == 3){
  344. echo json_encode( array('code' => 3, 'msg' => '订单未支付,无法核销' ) );
  345. die();
  346. }
  347. if($order_info['order_status_id'] != 4){
  348. echo json_encode( array('code' => 3, 'msg' => '订单状态不是核销阶段,无法核销' ) );
  349. die();
  350. }
  351. $hx_result = D('Home/Salesroom')->saleshexiao_order_goods($saleshexiao_info,$salesmember_id,$salesroom_id,$hx_times);
  352. if($hx_result == 1){
  353. echo json_encode( array('code' => 0) );
  354. }else if($hx_result == 0){
  355. echo json_encode( array('code' => 3, 'msg' => '核销商品失败') );
  356. }else{
  357. echo json_encode( array('code' => 3, 'msg' => '无核销权限') );
  358. }
  359. }
  360. /**
  361. * 核销员切换门店
  362. */
  363. public function hexiao_change_salesroom(){
  364. $_GPC = I('request.');
  365. $token = $_GPC['token'];
  366. $salesroom_id = $_GPC['salesroom_id'];
  367. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  368. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  369. {
  370. echo json_encode( array('code' => 1) );
  371. die();
  372. }
  373. $member_id = $weprogram_token['member_id'];
  374. $salesmember_id = D('Home/Salesroom')->get_salesmember_id_by_member_id($member_id);
  375. if( $salesmember_id <= 0 )
  376. {
  377. echo json_encode( array('code' => 3, 'msg' => '不是核销员' ) );
  378. die();
  379. }
  380. M('lionfish_comshop_salesroom_member')->where( array('id' => $salesmember_id ) )->save( array('last_salesroom_id' => $salesroom_id) );
  381. echo json_encode( array('code' => 0) );
  382. }
  383. }