Consult.php 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //竞价单(咨询单)
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  59. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  60. $role=$this->checkRole();
  61. if(!empty($role['write'])){
  62. $where[]=["b.createrid","in",$role['write']];
  63. }
  64. // if(!empty($role['platform']) ){
  65. // $where[]=["b.platform_code","in",$role['platform']];
  66. // }
  67. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  68. ->count();
  69. $total = ceil($count / $size);
  70. $page = $page >= $total ? $total : $page;
  71. $list = Db::name('consult_info')
  72. ->alias("a")
  73. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  74. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  75. ->where($where)
  76. ->page($page, $size)
  77. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  78. ->order("a.id desc")
  79. ->cursor();
  80. $data=[];
  81. foreach ($list as $value){
  82. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  83. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  84. true):[];
  85. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  86. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  87. $value['khname']="";
  88. if($value['khNo']!==""){
  89. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  90. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  91. }
  92. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  93. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  94. $data[]=$value;
  95. }
  96. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  97. }
  98. public function info(){
  99. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  100. if($id==""){
  101. return error_show(1002,"咨询单编号不能为空");
  102. }
  103. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  104. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  105. $fo['can']=$in;
  106. if(empty($fo)){
  107. return error_show(1002,"未找到咨询单编号");
  108. }else{
  109. return app_show(0,"获取成功",$fo);
  110. }
  111. }
  112. public function del(){
  113. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  114. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  115. if($de==false){
  116. return error_show(1002,'咨询单信息未找到');
  117. }
  118. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  119. if($dell){
  120. return error_show(0,"删除成功");
  121. }else
  122. return error_show(1002,"删除失败");
  123. }
  124. public function create(){
  125. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  126. if($is_project===""){
  127. return error_show(1002,"参数is_project不能为空");
  128. }
  129. if($is_project==1){
  130. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  131. if($projectNo===""){
  132. return error_show(1002,"参数projectNo不能为空");
  133. }
  134. }
  135. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  136. if($khNo===""){
  137. return error_show(1002,"参数khNo不能为空");
  138. }
  139. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  140. if($companyNo===""){
  141. return error_show(1002,"参数companyNo不能为空");
  142. }
  143. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  144. if($endtime===""){
  145. return error_show(1002,"参数endtime不能为空");
  146. }
  147. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  148. "";
  149. if($platform_code===""){
  150. return error_show(1002,"参数platform_code不能为空");
  151. }
  152. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  153. if($ladder==""){
  154. return error_show(1005,"参数ladder不能为空");
  155. }
  156. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  157. if($token==''){
  158. return error_show(105,"参数token不能为空");
  159. }
  160. $user =GetUserInfo($token);
  161. if(empty($user)||$user['code']!=0){
  162. return error_show(102,"用户数据不存在");
  163. }
  164. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  165. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  166. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  167. $zxNo=makeNo("ZX");
  168. Db::startTrans();
  169. try{
  170. $data=[
  171. "zxNo"=>$zxNo,
  172. "createrid"=>$createrid,
  173. "creater"=>$creater,
  174. "is_project"=>$is_project,
  175. "projectNo"=>isset($projectNo) ? $projectNo:"",
  176. "khNo"=>$khNo,
  177. "companyNo"=>$companyNo,
  178. "endtime"=>$endtime,
  179. "salesman"=>$creater,
  180. "platform_code"=>$platform_code,
  181. "saleid"=>$createrid,
  182. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  183. "status"=>0,
  184. "is_del"=>0,
  185. "addtime"=>date("Y-m-d H:i:s"),
  186. "updatetime"=>date("Y-m-d H:i:s"),
  187. ];
  188. $zx = Db::name("consult_order")->insert($data);
  189. if($zx){
  190. //判断是否是项目,且该项目是否存在台账记录中
  191. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  192. foreach ($ladder as $value){
  193. $infoNo=makeNo("IF");
  194. $specinfo=[];
  195. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  196. foreach ($value["specinfo"] as $v){
  197. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  198. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  199. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  200. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  201. $specinfo[]=$v;
  202. }
  203. }
  204. $info=[
  205. "infoNo"=>$infoNo,
  206. "zxNo"=>$zxNo,
  207. "spuCode"=>"",
  208. "good_name"=>$value['good_name'],
  209. "good_img"=>$value['good_img'],
  210. "cat_id"=>$value['cat_id'],
  211. "unit"=>$value['unit'],
  212. "brand_id"=>$value['brand_id'],
  213. "arrival_time"=>$value['arrival_time'],
  214. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  215. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  216. "is_addrs"=>$value['is_addrs'],
  217. "is_custom"=>$value['is_custom'],
  218. "metal_id"=>$value['metal_id'],
  219. "config"=>isset($value['config'])?$value['config']:"",
  220. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  221. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  222. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  223. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  224. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  225. "budget_price"=>$value['budget_price'],
  226. "num"=>$value['num'],
  227. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  228. "use_desc"=>$value['use_desc'],
  229. "remark"=>$value['remark'],
  230. "status"=>1,
  231. "is_del"=>0,
  232. "addtime"=>date("Y-m-d H:i:s"),
  233. "updatetime"=>date("Y-m-d H:i:s"),
  234. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  235. ];
  236. $up = Db::name("consult_info")->insertGetId($info);
  237. if(!$up){
  238. Db::rollback();
  239. return error_show(1004,'添加失败');
  240. }else{
  241. //修改状态
  242. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  243. "order_code" => $infoNo,//咨询单详情编号
  244. "status" => 1,//这里的status是之前的值
  245. "action_remark" => '',//备注
  246. "action_type" => "create"//新建create,编辑edit,更改状态status
  247. ], "ZXD", 1, $info);
  248. //竞价单不走流程,不推待办已办
  249. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  250. // "order_type" => 'ZXD',
  251. // "order_code" => $infoNo,//咨询单详情编号
  252. // "order_id" => $up,
  253. // "order_status" => 1,
  254. // 'before_status'=>0
  255. // ]);
  256. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  257. if (isset($stand_exists)) {
  258. Db::name('standing_book')
  259. ->where('id', $stand_exists['id'])
  260. ->update([
  261. 'infoNo' => $infoNo,
  262. 'updatetime' => date('Y-m-d H:i:s')
  263. ]);
  264. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  265. } else {
  266. //添加台账信息
  267. Db::name('standing_book')
  268. ->insert([
  269. 'standBookNo' => makeNo("IO"),
  270. 'projectNo' => isset($projectNo) ? $projectNo : '',
  271. 'infoNo' => $infoNo,
  272. 'companyNo' => $companyNo,
  273. 'customer_code' => $khNo,
  274. 'addtime' => date('Y-m-d H:i:s'),
  275. 'updatetime' => date('Y-m-d H:i:s')
  276. ]);
  277. }
  278. }
  279. }
  280. Db::commit();
  281. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  282. }else{
  283. Db::rollback();
  284. return error_show(1004,"新建失败");
  285. }
  286. }catch (\Exception $e){
  287. Db::rollback();
  288. return error_show(1003,$e->getMessage());
  289. }
  290. }
  291. public function zxinfo(){
  292. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  293. if($infoNo==""){
  294. return error_show(1004,"参数infoNo不能为空");
  295. }
  296. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  297. if($zxinfo==false){
  298. return error_show(1004,"未找到信息数据");
  299. }
  300. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  301. if($zxorder==false){
  302. return error_show(1004,"未找到咨询信息数据");
  303. }
  304. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  305. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  306. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  307. $zxinfo['khname']="";
  308. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  309. $zxinfo['khNo']="";
  310. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  311. $zxinfo['brand']="";
  312. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  313. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  314. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  315. $zxinfo['company']="";
  316. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  317. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  318. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  319. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  320. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  321. $zxinfo['project_name']="";
  322. $zxinfo['budget_total']="";
  323. $zxinfo['departinfo']=[];
  324. $zxinfo['unit_name']="";
  325. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  326. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  327. if($zxorder['khNo']!==""){
  328. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  329. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  330. $zxinfo['khNo']= $zxorder['khNo'];
  331. }
  332. if($zxinfo['unit']!==""){
  333. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  334. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  335. }
  336. if($zxinfo['brand_id']!==""){
  337. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  338. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  339. }
  340. if($zxorder['companyNo']!==""){
  341. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  342. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  343. }
  344. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  345. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  346. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  347. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  348. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  349. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  350. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  351. }
  352. if($zxorder['depart']>0){
  353. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  354. }
  355. if($zxorder['platform_code']>0){
  356. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  357. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  358. }
  359. return app_show(0,"获取成功",$zxinfo);
  360. }
  361. public function zxedit(){
  362. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  363. if($infoNo==""){
  364. return error_show(1004,"参数infoNo不能为空");
  365. }
  366. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  367. if($zxinfo==false){
  368. return error_show(1004,"未找到信息数据");
  369. }
  370. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  371. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  372. if($good_name==""){
  373. return error_show(1003,"参数good_name不能为空");
  374. }
  375. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  376. if($good_img==""){
  377. return error_show(1003,"参数good_img不能为空");
  378. }
  379. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  380. if($cat_id==""){
  381. return error_show(1003,"参数cat_id不能为空");
  382. }
  383. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  384. if($unit==""){
  385. return error_show(1003,"参数unit不能为空");
  386. }
  387. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  388. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  389. if($arrival_time==""){
  390. return error_show(1003,"参数arrival_time不能为空");
  391. }
  392. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  393. if($specin==""){
  394. return error_show(1003,"参数specinfo不能为空");
  395. }
  396. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  397. // if($cost_desc==""){
  398. // return error_show(1003,"参数cost_desc不能为空");
  399. // }
  400. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  401. if($is_addrs===""){
  402. return error_show(1003,"参数is_addrs不能为空");
  403. }
  404. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  405. if($is_custom===""){
  406. return error_show(1003,"参数is_custom不能为空");
  407. }
  408. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  409. if($metal_id===""){
  410. return error_show(1003,"参数metal_id不能为空");
  411. }
  412. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  413. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  414. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  415. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  416. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  417. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  418. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  419. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  420. if($num===""){
  421. return error_show(1003,"参数num不能为空");
  422. }
  423. if($budget_price===""){
  424. return error_show(1003,"参数budget_price不能为空");
  425. }
  426. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  427. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  428. if($use_desc==""){
  429. return error_show(1003,"参数use_desc不能为空");
  430. }
  431. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  432. if($remark==""){
  433. return error_show(1003,"参数remark不能为空");
  434. }
  435. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  436. if($endtime==""){
  437. return error_show(1003,"参数endtime不能为空");
  438. }
  439. if($metal_id!=0){
  440. if($config==""){
  441. return error_show(1003,"参数config不能为空");
  442. }
  443. if($other_config==""){
  444. return error_show(1003,"参数other_config不能为空");
  445. }
  446. if($specs_weight===""){
  447. return error_show(1003,"参数specs_weight不能为空");
  448. }
  449. if($gold_price===""){
  450. return error_show(1003,"参数gold_price不能为空");
  451. }
  452. }
  453. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  454. if($token==''){
  455. return error_show(102,"参数token不能为空");
  456. }
  457. $user =GetUserInfo($token);
  458. if(empty($user)||$user['code']!=0){
  459. return error_show(105,"用户数据不存在");
  460. }
  461. $specinfo=[];
  462. foreach ($specin as $v){
  463. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  464. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  465. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  466. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  467. $specinfo[]=$v;
  468. }
  469. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  470. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  471. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  472. Db::startTrans();
  473. try{
  474. $innew =makeNo("IF");
  475. $info=[
  476. "infoNo"=>$innew,
  477. "zxNo"=>$zxinfo['zxNo'],
  478. "spuCode"=>"",
  479. "good_name"=>$good_name,
  480. "good_img"=>$good_img,
  481. "cat_id"=>$cat_id,
  482. "unit"=>$unit,
  483. "brand_id"=>$brand_id,
  484. "arrival_time"=>$arrival_time,
  485. "specinfo"=>json_encode($specinfo),
  486. // "color"=>$color,
  487. // "material"=>$material,
  488. "cost_desc"=>$cost_desc,
  489. "is_addrs"=>$is_addrs,
  490. "is_custom"=>$is_custom,
  491. "metal_id"=>$metal_id,
  492. "config"=>$config,
  493. "other_config"=>$other_config,
  494. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  495. "gold_price"=>$gold_price===""? 0 : $gold_price,
  496. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  497. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  498. "budget_price"=>$budget_price,
  499. "num"=>$num,
  500. "pgNo"=>$pgNo,
  501. "use_desc"=>$use_desc,
  502. "remark"=>$remark,
  503. "bargain_num"=>$zxinfo['bargain_num']+1,
  504. "status"=>1,
  505. "is_del"=>0,
  506. "addtime"=>date("Y-m-d H:i:s"),
  507. "updatetime"=>date("Y-m-d H:i:s"),
  508. 'bargain_status'=>1,
  509. 'enclosure_file'=>$enclosure_file
  510. ];
  511. $up = Db::name("consult_info")->insert($info);
  512. if($up){
  513. //操作记录
  514. ActionLog::logAdd($this->post['token'], [
  515. "order_code" => $innew,//咨询单详情编号
  516. "status" => 1,//这里的status是之前的值
  517. "action_remark" => '',//备注
  518. "action_type" => "edit"//新建create,编辑edit,更改状态status
  519. ], "ZXD", 1, $this->post);
  520. // ProcessOrder::AddProcess($this->post['token'], [
  521. // "order_type" => 'ZXD',
  522. // "order_code" => $innew,//咨询单详情编号
  523. // "order_id" => 0,
  524. // "order_status" => 1
  525. // ]);
  526. if (!empty($bidlist)){
  527. foreach ($bidlist as $value){
  528. unset($value['id']);
  529. $value['infoNo']=$innew;
  530. $value['bidNo']=makeNo("BD");
  531. $value['spuCode']=makeNo("SKU");
  532. $value['status'] =0;
  533. $value['updatetime'] =date("Y-m-d H:i:s");
  534. $in = Db::name("consult_bids")->insert($value);
  535. if($in==false){
  536. Db::rollback();
  537. return error_show(1004,"反馈商品新建失败");
  538. }
  539. ActionLog::logAdd($this->post['token'], [
  540. "order_code" => $innew,//咨询单详情编号
  541. "status" => 1,//这里的status是之前的值
  542. "action_remark" => '',//备注
  543. "action_type" => "edit"//新建create,编辑edit,更改状态status
  544. ], "FKD", 1, $this->post);
  545. }
  546. }
  547. $zxinfo["bargain_status"] =1;
  548. $zxinfo["status"] =6;
  549. $zxinfo["bargain_code"] =$innew;
  550. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  551. $bar=Db::name("consult_info")->save($zxinfo);
  552. if($bar==false){
  553. Db::rollback();
  554. return error_show(1004,"反馈商品更新失败");
  555. }else{
  556. //修改状态,添加待办
  557. ActionLog::logAdd($this->post['token'], [
  558. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  559. "status" => $zxinfo['status'],//这里的status是之前的值
  560. "action_remark" => '',//备注
  561. "action_type" => "edit"//新建create,编辑edit,更改状态status
  562. ], "ZXD", $zxinfo['status'], $zxinfo);
  563. }
  564. //更新consule_order记录
  565. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  566. 'updatetime'=>date('Y-m-d H:i:s')]);
  567. if($op==false){
  568. Db::rollback();
  569. return error_show(1004,'咨询单结束时间更新失败');
  570. }
  571. //维护台账记录
  572. $insert_standing_book_data=[
  573. 'standBookNo'=>makeNo('IO'),
  574. 'infoNo'=>$innew,
  575. 'addtime' => date('Y-m-d H:i:s'),
  576. 'updatetime' => date('Y-m-d H:i:s')
  577. ];
  578. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  579. if(!empty($temp_project)){
  580. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  581. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  582. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  583. }
  584. Db::name('standing_book')->insert($insert_standing_book_data);
  585. Db::commit();
  586. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  587. }
  588. }catch (\Exception $e){
  589. Db::rollback();
  590. return error_show(1004,$e->getMessage());
  591. }
  592. }
  593. //** 发布竞标任务 */
  594. public function bargain(){
  595. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  596. if($infoNo==""){
  597. return error_show(1004,"参数infoNo不能为空");
  598. }
  599. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  600. if($zxinfo==false){
  601. return error_show(1004,"未找到信息数据");
  602. }
  603. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  604. if($status===""){
  605. return error_show(1004,"参数status不能为空");
  606. }
  607. // if($status==1&&$zxinfo['status']>1){
  608. // $zxinfo['bargain_num']=+1;
  609. // }
  610. $old_zxinfo_status = $zxinfo['status'];
  611. $zxinfo['status']=$status;
  612. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  613. $up = Db::name("consult_info")->save($zxinfo);
  614. if($up){
  615. //修改状态,添加待办
  616. ActionLog::logAdd($this->post['token'], [
  617. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  618. "status" => $old_zxinfo_status,//这里的status是之前的值
  619. "action_remark" => '',//备注
  620. "action_type" => "status"//新建create,编辑edit,更改状态status
  621. ], "ZXD", $zxinfo['status'], $zxinfo);
  622. return app_show(0,"状态更新成功");
  623. }else{
  624. return error_show(1003,"状态更新失败");
  625. }
  626. }
  627. //反馈商品添加
  628. public function feadback(){
  629. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  630. if($infoNo==""){
  631. return error_show(1002,"参数infoNo不能为空");
  632. }
  633. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  634. if($zxinfo==false){
  635. return error_show(1003,"未找到信息数据");
  636. }
  637. if($zxinfo['status']!=1){
  638. return error_show(1004,"任务未进行");
  639. }
  640. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  641. if($zx==false){
  642. return error_show(1003,"未找咨询信息数据");
  643. }
  644. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  645. if($pname==""){
  646. return error_show(1002,"参数pname不能为空");
  647. }
  648. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  649. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  650. if($cat_id==""){
  651. return error_show(1002,"参数cat_id不能为空");
  652. }
  653. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  654. if($specin==""){
  655. return error_show(1003,"参数specinfo不能为空");
  656. }
  657. $specinfo=[];
  658. foreach ($specin as $v){
  659. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  660. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  661. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  662. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  663. $specinfo[]=$v;
  664. }
  665. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  666. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  667. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  668. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  669. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  670. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  671. :"";
  672. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  673. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  674. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  675. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  676. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  677. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  678. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  679. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  680. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  681. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  682. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  683. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  684. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  685. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  686. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  687. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  688. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  689. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  690. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  691. if($nake_fee==="" ){
  692. return error_show(1004,"参数nake_fee不能为空");
  693. }
  694. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  695. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  696. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  697. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  698. if($delivery_place==''){
  699. return error_show(1002,"参数delivery_place不能为空");
  700. }
  701. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  702. if($token==''){
  703. return error_show(1002,"参数token不能为空");
  704. }
  705. $user =GetUserInfo($token);
  706. if(empty($user)||$user['code']!=0){
  707. return error_show(1005,"用户数据不存在");
  708. }
  709. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  710. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  711. $bidNo=makeNo("BD");
  712. $spucode=makeNo("SKU");
  713. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  714. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  715. //部分参数的大小校验
  716. $vali = Validate::rule([
  717. 'expire_day|有效时长'=>'require|elt:214748364',
  718. 'delivery_day|物流时长'=>'require|elt:214748364',
  719. 'work_day|生产工期'=>'require|elt:214748364',
  720. 'weight|总重量'=>'require|max:10',
  721. ]);
  722. $temp = [
  723. 'expire_day'=>$expire_day,
  724. 'delivery_day'=>$delivery_day,
  725. 'work_day'=>$work_day,
  726. 'weight'=>$weight,
  727. ];
  728. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  729. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  730. $cat_top_list = made($cat_id);
  731. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  732. if ($is_gold_price == 1 && $cat_top_id == 6) {
  733. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  734. ->find();
  735. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  736. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  737. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  738. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  739. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  740. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  741. $saleprice = $total_fee/ (1 - $budget);
  742. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  743. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  744. }else{
  745. if($nake_fee){
  746. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  747. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  748. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  749. }else{
  750. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  751. (1 - $budget);
  752. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  753. }
  754. }
  755. $data=[
  756. "bidNo"=>$bidNo,
  757. "infoNo"=>$infoNo,
  758. "zxNo"=>$zxinfo['zxNo'],
  759. "spuCode"=>$spucode,
  760. "good_name"=>$pname,
  761. "brand_id"=>$brandid,
  762. "cat_id"=>$cat_id,
  763. "specinfo"=>json_encode($specinfo),
  764. "unit_id"=>$unit_id,
  765. "cost_desc"=>$cost_desc,
  766. "work_day"=>$work_day,
  767. "delivery_day"=>$delivery_day,
  768. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  769. "expire_day"=>$expire_day,
  770. "origin_place"=>$origin_place,
  771. "supplierNo"=>$supplierNo,
  772. "pay_way"=>$pay_way,
  773. "tax"=>$tax,
  774. "send_way"=>$send_way,
  775. "metal_id"=>$metal_id,
  776. "is_gold_price"=>$is_gold_price,
  777. "config"=>$config,
  778. "other_config"=>$other_config,
  779. "weight"=>$weight,
  780. "good_weight"=>$good_weight,
  781. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  782. "is_diff"=>$is_diff,
  783. "demo_fee"=>$demo_fee,
  784. "delivery_fee"=>$delivery_fee,
  785. "open_fee"=>$open_fee,
  786. "pakge_fee"=>$pakge_fee,
  787. "nake_fee"=>$nake_fee,
  788. "mark_fee"=>$mark_fee,
  789. "cert_fee"=>$cert_fee,
  790. "cost_fee"=>$cost_fee,
  791. "total_fee"=>$total_fee,
  792. "supply_area"=>$supply_area,
  793. "remark"=>$remark,
  794. "sale_price"=>$saleprice,
  795. "sale_cost_fee"=>$sale_cost_fee,
  796. "origin_cost_fee"=>$sale_cost_fee,
  797. "origin_price"=>$saleprice,
  798. "createrid"=>$createrid,
  799. "creater"=>$creater,
  800. "status"=>$zxinfo['status']==1 ?1 :2,
  801. "is_del"=>0,
  802. "addtime"=>date("Y-m-d H:i:s"),
  803. "updatetime"=>date("Y-m-d H:i:s"),
  804. 'delivery_place'=>$delivery_place//发货地
  805. ];
  806. Db::startTrans();
  807. try{
  808. $insert= Db::name("consult_bids")->insert($data);
  809. if($insert){
  810. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  811. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  812. if($projectinfo==false){
  813. Db::rollback();
  814. return error_show(1006,"未找到项目信息");
  815. }
  816. $temp=[];
  817. $temp['spuCode']=$spucode;
  818. $temp['skuCode']="";
  819. $temp['pgNo']=$zxinfo['pgNo'];
  820. $temp['projectNo']=$zx['projectNo'];
  821. $temp['good_name']=$pname;
  822. $temp['good_type']=$projectinfo['good_type'];
  823. $temp['data_source']=2;
  824. $temp['cat_id']=$cat_id;
  825. $temp['budget_price']=$projectinfo['budget_price'];
  826. $temp['sale_price']=$saleprice;
  827. $temp['origin_price']=$total_fee;
  828. $temp['num']=$zxinfo['num'];
  829. $temp['status']=0;
  830. $temp['is_del']=0;
  831. $temp['creater']=$creater;
  832. $temp['createrid']=$createrid;
  833. $temp['addtime']=date("Y-m-d H:i:s");
  834. $temp['updatetime']=date("Y-m-d H:i:s");
  835. $nu = Db::name("project_feedback")->insert($temp);
  836. if($nu==false){
  837. Db::rollback();
  838. return error_show(1006,"项目反馈失败");
  839. }else{
  840. $old_projectinfo_status = $projectinfo['status'];
  841. $projectinfo['status']=2;
  842. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  843. $up = Db::name("project_info")->save($projectinfo);
  844. if($up){
  845. //修改状态,添加待办,只记录动作
  846. ActionLog::logAdd($this->post['token'], [
  847. "order_code" => $projectinfo['pgNo'],//编码
  848. "status" => $old_projectinfo_status,//这里的status是之前的值
  849. "action_remark" => '',//备注
  850. "action_type" => "status"//新建create,编辑edit,更改状态status
  851. ], "PRI", 2, $projectinfo);
  852. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  853. ->count();
  854. if($count==0){
  855. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  856. if($projetc!=false){
  857. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  858. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  859. if($proc==false){
  860. Db::rollback();
  861. return error_show(1006,"项目反馈失败");
  862. }else{
  863. //修改状态,添加待办
  864. ActionLog::logAdd($this->post['token'], [
  865. "order_code" => $projetc['projectNo'],//项目编码
  866. "status" => 1,//这里的status是之前的值
  867. "action_remark" => '',//备注
  868. "action_type" => "status"//新建create,编辑edit,更改状态status
  869. ], "PRO", 2, $projetc);
  870. ProcessOrder::AddProcess($this->post['token'], [
  871. "order_type" => 'PRO',
  872. "order_code" => $projetc['projectNo'],
  873. "order_id" => $projetc['id'],
  874. "order_status" => 2,"before_status"=>1
  875. ]);
  876. }
  877. }
  878. }
  879. }
  880. }
  881. }
  882. Db::commit();
  883. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  884. }else{
  885. Db::rollback();
  886. return error_show(1006,"反馈失败");
  887. }
  888. }catch (\Exception $e){
  889. Db::rollback();
  890. return error_show(1006,$e->getMessage());
  891. }
  892. }
  893. //反馈商品详情
  894. public function feadinfo(){
  895. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  896. if($bidNo==""){
  897. return error_show(1004,"参数bidNo不能为空");
  898. }
  899. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  900. if($info==false){
  901. return error_show(1004,"未找到商品数据");
  902. }
  903. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  904. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  905. $info['cat_info'] = made($info['cat_id'],[]);
  906. $info['noble_weight'] = $info['good_weight'];
  907. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  908. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  909. if($info['brand_id']!=0){
  910. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  911. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  912. }else{
  913. $info["brand_name"]="";
  914. $info["brand_id"]="";
  915. }
  916. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  917. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  918. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  919. $god=[
  920. "metal_id"=>$info['metal_id'],
  921. "weight"=>$info["good_weight"],
  922. "demo_fee"=>$info["demo_fee"],
  923. "delivery_fee"=>$info["delivery_fee"],
  924. "open_fee"=>$info["open_fee"],
  925. "packing_fee"=>$info["pakge_fee"],
  926. "mark_fee"=>$info["mark_fee"],
  927. "nake_fee"=>$info["nake_fee"],
  928. "cert_fee"=>$info["cert_fee"],
  929. "cost_fee"=>$info["cost_fee"],
  930. "num"=>$bidinfo["num"],
  931. ];
  932. if($info['is_gold_price']==1){
  933. $price = GoldPrice($god, $budget/100);
  934. $info['sale_price'] =round($price,2);
  935. }
  936. $info['specinfo'] = json_decode($info['specinfo'],true);
  937. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  938. if($info['delivery_place']!=""){
  939. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  940. }
  941. $info['delivery_place_cn']=GetAddr(json_encode($place));
  942. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  943. if($info['origin_place']!=""){
  944. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  945. }
  946. $info['origin_place_cn']=GetAddr(json_encode($place));
  947. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  948. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  949. $info['bargain'] =$bargain;
  950. $info['good_img'] = explode(',',$info['good_img']);
  951. return app_show(0,"获取成功",$info);
  952. }
  953. //反馈商品编辑
  954. public function feededit(){
  955. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  956. if($bidNo==""){
  957. return error_show(1002,"参数bidNo不能为空");
  958. }
  959. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  960. if($bidinfo==false){
  961. return error_show(1003,"未找到信息数据");
  962. }
  963. if($bidinfo['status']>=5){
  964. return error_show(1004,"咨询单已确认无法修改");
  965. }
  966. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  967. if($zxinfo==false){
  968. return error_show(1003,"未找到信息数据");
  969. }
  970. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  971. if($zx==false){
  972. return error_show(1003,"未找咨询信息数据");
  973. }
  974. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  975. if($pname==""){
  976. return error_show(1002,"参数pname不能为空");
  977. }
  978. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  979. // if($brandid==""){
  980. // return error_show(1002,"参数brandid不能为空");
  981. // }
  982. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  983. if($cat_id==""){
  984. return error_show(1002,"参数cat_id不能为空");
  985. }
  986. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  987. if($specin==""){
  988. return error_show(1003,"参数specinfo不能为空");
  989. }
  990. $specinfo=[];
  991. foreach ($specin as $v){
  992. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  993. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  994. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  995. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  996. $specinfo[]=$v;
  997. }
  998. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  999. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1000. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1001. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1002. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1003. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1004. :"";
  1005. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1006. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1007. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1008. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1009. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1010. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1011. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1012. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1013. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1014. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1015. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1016. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1017. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1018. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1019. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1020. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1021. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1022. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1023. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1024. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1025. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1026. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1027. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1028. if($delivery_place==''){
  1029. return error_show(1002,"参数delivery_place不能为空");
  1030. }
  1031. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1032. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1033. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1034. $cat_top_list = made($cat_id);
  1035. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1036. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1037. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1038. ->find();
  1039. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1040. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1041. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1042. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1043. $saleprice = $total_fee / (1 - $budget);
  1044. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1045. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1046. }else{
  1047. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1048. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1049. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1050. }
  1051. Db::startTrans();
  1052. try{
  1053. $data=[
  1054. "good_name"=>$pname,
  1055. "brand_id"=>$brandid,
  1056. "cat_id"=>$cat_id,
  1057. "specinfo"=>json_encode($specinfo),
  1058. // "material"=>$material,
  1059. "unit_id"=>$unit_id,
  1060. "cost_desc"=>$cost_desc,
  1061. "work_day"=>$work_day,
  1062. "delivery_day"=>$delivery_day,
  1063. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1064. "expire_day"=>$expire_day,
  1065. "origin_place"=>$origin_place,
  1066. "supplierNo"=>$supplierNo,
  1067. "pay_way"=>$pay_way,
  1068. "tax"=>$tax,
  1069. "send_way"=>$send_way,
  1070. "metal_id"=>$metal_id,
  1071. "is_gold_price"=>$is_gold_price,
  1072. "config"=>$config,
  1073. "other_config"=>$other_config,
  1074. "weight"=>$weight,
  1075. "good_weight"=>$noble_weight,
  1076. "is_diff"=>$is_diff,
  1077. "demo_fee"=>$demo_fee,
  1078. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1079. "delivery_fee"=>$delivery_fee,
  1080. "open_fee"=>$open_fee,
  1081. "pakge_fee"=>$pakge_fee,
  1082. "nake_fee"=>$nake_fee,
  1083. "mark_fee"=>$mark_fee,
  1084. "cert_fee"=>$cert_fee,
  1085. "cost_fee"=>$cost_fee,
  1086. "sale_cost_fee"=>$sale_cost_fee,
  1087. "origin_cost_fee"=>$sale_cost_fee,
  1088. "total_fee"=>$total_fee,
  1089. "sale_price"=>$saleprice,
  1090. "origin_price"=>$saleprice,
  1091. "supply_area"=>$supply_area,
  1092. "remark"=>$remark,
  1093. "status"=>0,
  1094. "updatetime"=>date("Y-m-d H:i:s"),
  1095. 'delivery_place' => $delivery_place
  1096. ];
  1097. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1098. if($insert){
  1099. if($zxinfo['bargain_status']==1){
  1100. $zxinfo['bargain_status']=0;
  1101. $infoip =Db::name("consult_info")->save($zxinfo);
  1102. if($infoip==false){
  1103. Db::rollback();
  1104. return error_show(1006,"咨询信息状态更新失败");
  1105. }
  1106. }
  1107. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1108. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1109. if($projectinfo==false){
  1110. Db::rollback();
  1111. return error_show(1006,"未找到项目信息");
  1112. }
  1113. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1114. if($feed!=false) {
  1115. $feed['good_name']=$pname;
  1116. $feed['good_type']=$projectinfo['good_type'];
  1117. $feed['cat_id']=$cat_id;
  1118. $feed['sale_price']=$saleprice;
  1119. $feed['origin_price']=$total_fee;
  1120. $feed['updatetime']=date("Y-m-d H:i:s");
  1121. $temp['updatetime']=date("Y-m-d H:i:s");
  1122. $nu=Db::name("project_feedback")->save($feed);
  1123. if ($nu == false) {
  1124. Db::rollback();
  1125. return error_show(1006 , "项目反馈失败");
  1126. } else {
  1127. $old_projectinfo_status=$projectinfo['status'];
  1128. $projectinfo['status']=2;
  1129. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1130. $up=Db::name("project_info")->save($projectinfo);
  1131. if ($up) {
  1132. //修改状态,添加待办,只记录动作
  1133. ActionLog::logAdd($this->post['token'] , [
  1134. "order_code"=>$projectinfo['pgNo'] ,//编码
  1135. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1136. "action_remark"=>'' ,//备注
  1137. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1138. ] , "PRI" , 2 , $projectinfo
  1139. );
  1140. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1141. if ($count == 0) {
  1142. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1143. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1144. if ($project_id) {
  1145. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1146. if ($proc == false) {
  1147. Db::rollback();
  1148. return error_show(1006 , "项目反馈失败");
  1149. } else {
  1150. //修改状态,添加待办
  1151. ActionLog::logAdd($this->post['token'] , [
  1152. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1153. "status"=>1 ,//这里的status是之前的值
  1154. "action_remark"=>'' ,//备注
  1155. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1156. ] , "PRO" , 2 , $this->post
  1157. );
  1158. ProcessOrder::AddProcess($this->post['token'] , [
  1159. "order_type"=>'PRO' ,
  1160. "order_code"=>$projectinfo['projectNo'] ,
  1161. "order_id"=>$project_id ,
  1162. "order_status"=>2 , "before_status"=>1
  1163. ]
  1164. );
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. Db::commit();
  1173. return app_show(0,"编辑成功");
  1174. }else{
  1175. Db::rollback();
  1176. return error_show(1004,"编辑失败");
  1177. }
  1178. }catch (\Exception $e){
  1179. Db::rollback();
  1180. return error_show(1004,$e->getMessage());
  1181. }
  1182. }
  1183. //生成议价单
  1184. public function bargain_add(){
  1185. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1186. if($bidNo===""){
  1187. return error_show(1004,"参数bidNo不能为空");
  1188. }
  1189. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1190. if($info==false){
  1191. return error_show(1004,"未找到商品数据");
  1192. }
  1193. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1194. if($consult==false){
  1195. return error_show(1004,"未找到咨询数据");
  1196. }
  1197. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1198. if($bargain_price===""){
  1199. return error_show(1004,"参数bargain_price不能为空");
  1200. }
  1201. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1202. if($info['is_gold_price']==1){
  1203. if($cost_price==""){
  1204. return error_show(1004,"参数cost_price不能为空");
  1205. }
  1206. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1207. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1208. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1209. ->find();
  1210. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1211. }
  1212. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1213. // if($bargain_reason===""){
  1214. // return error_show(1004,"参数bargain_reason不能为空");
  1215. // }
  1216. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1217. if($infos==false){
  1218. return error_show(1004,"未找到商品数据");
  1219. }
  1220. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1221. return error_show(1004,"咨询单招标未结束或已确认商品");
  1222. }
  1223. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1224. if($token==''){
  1225. return error_show(105,"参数token不能为空");
  1226. }
  1227. $user =GetUserInfo($token);
  1228. if(empty($user)||$user['code']!=0){
  1229. return error_show(1002,"用户数据不存在");
  1230. }
  1231. //新增两个字段
  1232. //议价备注
  1233. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1234. //议价原因id
  1235. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1236. if ($result_info_id != '') {
  1237. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1238. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1239. }
  1240. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1241. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1242. $bargainNo =makeNo("BA");
  1243. Db::startTrans();//::todo 金价 毛利计算
  1244. try{
  1245. $data=[
  1246. "bidsNo"=>$bidNo,
  1247. "infoNo"=>$info['infoNo'],
  1248. "zxNo"=>$info['zxNo'],
  1249. "bargainNo"=>$bargainNo,
  1250. "bargain_type"=>1,
  1251. "bargain_reason"=>$bargain_reason,
  1252. "sale_price"=>$info['sale_price'],
  1253. "cost_before_price"=>$info['sale_cost_fee'],
  1254. "cost_after_price"=>$cost_price,
  1255. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1256. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1257. "after_price"=>$bargain_price,
  1258. "exam_info"=>"",
  1259. "status"=>0,
  1260. "is_del"=>0,
  1261. "creater"=>$creater,
  1262. "createrid"=>$createrid,
  1263. "addtime"=>date("Y-m-d H:i:s"),
  1264. "updatetime"=>date("Y-m-d H:i:s"),
  1265. 'bargain_remark'=>$bargain_remark,
  1266. 'result_info_id'=>$result_info_id,
  1267. ];
  1268. $int = Db::name("bargain_order")->insert($data);
  1269. if($int){
  1270. //修改状态,添加待办
  1271. ActionLog::logAdd($this->post['token'], [
  1272. "order_code" => $bargainNo,//咨询单详情编号
  1273. "status" => 0,//这里的status是之前的值
  1274. "action_remark" => '',//备注
  1275. "action_type" => "status"//新建create,编辑edit,更改状态status
  1276. ], "YJD", $data['status'], $data);
  1277. ProcessOrder::AddProcess($this->post['token'], [
  1278. "order_type" => 'YJD',
  1279. "order_code" => $bargainNo,
  1280. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1281. "order_status" =>0,"before_status"=>0
  1282. ]);
  1283. $odlstatus=$info['status'];
  1284. $info['status']=3;
  1285. $info['updatetime']=date("Y-m-d H:i:s");
  1286. $up =Db::name("consult_bids")->save($info);
  1287. if($up){
  1288. //修改状态,添加待办
  1289. ActionLog::logAdd($this->post['token'], [
  1290. "order_code" => $bidNo,//咨询单详情编号
  1291. "status" => $odlstatus,//这里的status是之前的值
  1292. "action_remark" => '',//备注
  1293. "action_type" => "status"//新建create,编辑edit,更改状态status
  1294. ], "FKD", $info['status'], $info);
  1295. $old_infos_status = $infos['status'];
  1296. $infos['status']=3;
  1297. $infos['updatetime']=date("Y-m-d H:i:s");
  1298. $ups =Db::name("consult_info")->save($infos);
  1299. if($ups){
  1300. //修改状态,添加待办
  1301. ActionLog::logAdd($this->post['token'], [
  1302. "order_code" => $infos['infoNo'],//咨询单详情编号
  1303. "status" => $old_infos_status,//这里的status是之前的值
  1304. "action_remark" => '',//备注
  1305. "action_type" => "status"//新建create,编辑edit,更改状态status
  1306. ], "ZXD", $infos['status'], $infos);
  1307. //维护台账信息
  1308. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1309. Db::commit();
  1310. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1311. }
  1312. }
  1313. }
  1314. Db::rollback();
  1315. return error_show(1004,"议价单新建失败");
  1316. }catch (\Exception $e){
  1317. Db::rollback();
  1318. return error_show(1004,$e->getMessage());
  1319. }
  1320. }
  1321. //选择商品
  1322. public function bids_check(){
  1323. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1324. if($bidNo===""){
  1325. return error_show(1004,"参数bidNo不能为空");
  1326. }
  1327. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1328. if($info==false){
  1329. return error_show(1004,"未找到商品数据");
  1330. }
  1331. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1332. if($infos==false){
  1333. return error_show(1004,"未找到商品数据");
  1334. }
  1335. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1336. return error_show(1004,"咨询单招标未结束或已确认商品");
  1337. }
  1338. Db::startTrans();
  1339. try {
  1340. $oldstattus=$info['status'];
  1341. $info['status']=6;
  1342. $info['updatetime']=date("Y-m-d H:i:s");
  1343. $bids = Db::name("consult_bids")->save($info);
  1344. if($bids){
  1345. //修改状态,添加待办
  1346. ActionLog::logAdd($this->post['token'], [
  1347. "order_code" =>$bidNo,//咨询单详情编号
  1348. "status" => $oldstattus,//这里的status是之前的值
  1349. "action_remark" => '',//备注
  1350. "action_type" => "status"//新建create,编辑edit,更改状态status
  1351. ], "FKD", $info['status'], $info);
  1352. $old_infos_status = $infos['status'];
  1353. $infos['status']=4;
  1354. $infos['updatetime']=date("Y-m-d H:i:s");
  1355. $se = Db::name("consult_info")->save($infos);
  1356. if($se){
  1357. //修改状态,添加待办
  1358. ActionLog::logAdd($this->post['token'], [
  1359. "order_code" => $infos['infoNo'],//咨询单详情编号
  1360. "status" => $old_infos_status,//这里的status是之前的值
  1361. "action_remark" => '',//备注
  1362. "action_type" => "status"//新建create,编辑edit,更改状态status
  1363. ], "ZXD", $infos['status'], $infos);
  1364. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1365. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1366. Db::commit();
  1367. return app_show(0,"商品确定成功");
  1368. }
  1369. }
  1370. Db::rollback();
  1371. return error_show(1004,"商品确认失败");
  1372. }catch (\Exception $e){
  1373. Db::rollback();
  1374. return error_show(1004,$e->getMessage());
  1375. }
  1376. }
  1377. //议价审核
  1378. /**
  1379. * status:
  1380. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1381. */
  1382. public function bargain_status(){
  1383. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1384. if($bargainNo===""){
  1385. return error_show(1004,"参数bargainNo不能为空");
  1386. }
  1387. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1388. if($info==false){
  1389. return error_show(1004,"未找到议价数据");
  1390. }
  1391. if($info['status']==12){
  1392. return error_show(1004,"议价单已取消");
  1393. }
  1394. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1395. if($bids==false){
  1396. return error_show(1004,"未找到商品数据");
  1397. }
  1398. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1399. if($coninfo==false){
  1400. return error_show(1004,"未找到咨询单数据");
  1401. }
  1402. if($bids['status']==6){
  1403. return error_show(1004,"咨询已选择商品");
  1404. }
  1405. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1406. if($status===''){
  1407. return error_show(1005,"参数status不能为空");
  1408. }
  1409. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1410. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1411. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1412. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1413. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1414. if($bids['is_gold_price']==1){
  1415. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1416. ->find();
  1417. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1418. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1419. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1420. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1421. $saleprice =$total_fe / (1 - $budget);
  1422. $rate_price = $total_fe / (1 - $rate);
  1423. $money_price =$total_fe / (1 - $money_rate);
  1424. $lower_price =$total_fe / (1 - $lower_rate);
  1425. }else{
  1426. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1427. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1428. if($bids['nake_fee']!=0){
  1429. $saleprice = ($total_fe)/ (1 - $budget);
  1430. $rate_price = ($total_fe)/ (1 - $rate);
  1431. $money_price =($total_fe)/ (1 - $money_rate);
  1432. $lower_price = ($total_fe) / (1 - $lower_rate);
  1433. }else{
  1434. $saleprice = $total_fe / (1 - $budget);
  1435. $rate_price =$total_fe/ (1 - $rate);
  1436. $money_price =$total_fe / (1 - $money_rate);
  1437. $lower_price = $total_fe/ (1 - $lower_rate);
  1438. }
  1439. }
  1440. $ra_status = $info['status'];
  1441. if($status==1){
  1442. if($info['status']==0){
  1443. if($info['after_price']<$rate_price){
  1444. $info['status']=2;
  1445. }else{
  1446. $info['status']=1;
  1447. }
  1448. }elseif($info['status']==2){
  1449. $info['status']=4;
  1450. }elseif($info['status']==4||$info['status']==5){
  1451. if($info['after_price']<$money_price){
  1452. $info['status']=7;
  1453. }else{
  1454. $info['status']=6;
  1455. }
  1456. }elseif($info['status']==7){
  1457. $info['lower_price'] =$lower_price;
  1458. if($info['after_price']<$lower_price){
  1459. $info['status']=10;
  1460. }else{
  1461. $info['status']=9;
  1462. }
  1463. }
  1464. }else{
  1465. if($info['status']==0){
  1466. $info['status']=3;
  1467. }elseif($info['status']==2){
  1468. $info['status']=4;
  1469. }elseif($info['status']==4||$info['status']==5){
  1470. $info['status']=8;
  1471. }elseif($info['status']==7){
  1472. $info['lower_price'] =$lower_price;
  1473. $info['status']=11;
  1474. }
  1475. }
  1476. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1477. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1478. if($token==''){
  1479. return error_show(105,"参数token不能为空");
  1480. }
  1481. $user =GetUserInfo($token);
  1482. if(empty($user)||$user['code']!=0){
  1483. return error_show(1002,"用户数据不存在");
  1484. }
  1485. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1486. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1487. Db::startTrans();
  1488. try{
  1489. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1490. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1491. "creater"=>$creater];
  1492. // $info['status'] =$status;
  1493. $info['remark'] =$remark;
  1494. $info['exam_info']=json_encode($examinfo) ;
  1495. $info['updatetime'] =date("Y-m-d H:i:s");
  1496. $up =Db::name("bargain_order")->save($info);
  1497. if($up){
  1498. //修改状态,添加待办
  1499. ActionLog::logAdd($this->post['token'], [
  1500. "order_code" => $bargainNo,//咨询单详情编号
  1501. "status" =>$ra_status,//这里的status是之前的值
  1502. "action_remark" => '',//备注
  1503. "action_type" => "status"//新建create,编辑edit,更改状态status
  1504. ], "YJD", $info['status'], $info);
  1505. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1506. ProcessOrder::AddProcess($token,$process);
  1507. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1508. $bidstatus=$bids['status'];
  1509. $bids['status']=5;
  1510. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1511. $bids['sale_price']=$info['after_price'];
  1512. if($bids['is_gold_price']==1){
  1513. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1514. // ->find();
  1515. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1516. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1517. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1518. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1519. }
  1520. }
  1521. $bids['updatetime']=date("Y-m-d H:i:s");
  1522. $up =Db::name("consult_bids")->save($bids);
  1523. if($up==false){
  1524. Db::rollback();
  1525. return error_show(1004,"数据更新失败");
  1526. }
  1527. ActionLog::logAdd($this->post['token'], [
  1528. "order_code" => $info["bidsNo"],//咨询单详情编号
  1529. "status" => $bidstatus,//这里的status是之前的值
  1530. "action_remark" => '',//备注
  1531. "action_type" => "status"//新建create,编辑edit,更改状态status
  1532. ], "FKD", $bids['status'], $bids);
  1533. }
  1534. Db::commit();
  1535. return app_show(0,"更新成功");
  1536. }
  1537. }catch (\Exception $e){
  1538. Db::rollback();
  1539. return error_show(1004,$e->getMessage());
  1540. }
  1541. }
  1542. public function bargain_info(){
  1543. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1544. if($bargainNo===""){
  1545. return error_show(1004,"参数bargainNo不能为空");
  1546. }
  1547. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1548. if($info==false){
  1549. return error_show(1004,"未找到议价数据");
  1550. }
  1551. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1552. if($bidinfos==false){
  1553. return error_show(1004,"未找到商品数据");
  1554. }
  1555. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1556. if($consultinfos==false){
  1557. return error_show(1004,"未找到咨询商品数据");
  1558. }
  1559. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1560. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1561. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1562. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1563. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1564. $info['before_rate'] =round($info['before_rate']*100,2);
  1565. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1566. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1567. $info['after_rate'] = round($info['after_rate']*100,2);
  1568. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1569. if($bidinfos['brand_id']!=0){
  1570. $info['brand_id'] = $bidinfos['brand_id'];
  1571. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1572. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1573. }else{
  1574. $info["brand_name"]="";
  1575. $info["brand_id"]="";
  1576. }
  1577. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1578. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1579. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1580. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1581. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1582. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1583. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1584. $info['budget'] =$budget;
  1585. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1586. if($info['after_rate']>=$catinfo['rate']){
  1587. //业务主管利率
  1588. $info['rate_status'] =1;
  1589. }
  1590. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1591. //财务主管利率
  1592. $info['rate_status'] =2;
  1593. }
  1594. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1595. //boss利率
  1596. $info['rate_status'] =3;
  1597. }
  1598. $god=[
  1599. "metal_id"=>$bidinfos['metal_id'],
  1600. "weight"=>$bidinfos["good_weight"],
  1601. "demo_fee"=>$bidinfos["demo_fee"],
  1602. "delivery_fee"=>$bidinfos["delivery_fee"],
  1603. "open_fee"=>$bidinfos["open_fee"],
  1604. "packing_fee"=>$bidinfos["pakge_fee"],
  1605. "mark_fee"=>$bidinfos["mark_fee"],
  1606. "nake_fee"=>$bidinfos["nake_fee"],
  1607. "cert_fee"=>$bidinfos["cert_fee"],
  1608. "cost_fee"=>$bidinfos["cost_fee"],
  1609. "num"=>$bidinfoe["num"],
  1610. ];
  1611. $info['gold_price']=0;
  1612. $info['noble_weight']=$bidinfos['good_weight'];
  1613. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1614. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1615. ->find();
  1616. $info['gold_price'] =$gold['price'];
  1617. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1618. }else{
  1619. if($bidinfos['nake_fee']!=0){
  1620. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1621. }else{
  1622. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1623. }
  1624. }
  1625. $info['cost_desc'] =$bidinfos['cost_desc'];
  1626. $info['work_day'] =$bidinfos['work_day'];
  1627. $info['delivery_day'] =$bidinfos['delivery_day'];
  1628. $info['expire_day'] =$bidinfos['expire_day'];
  1629. $info['origin_place'] =$bidinfos['origin_place'];
  1630. $info['origin_addr'] ="";
  1631. if($bidinfos['origin_place']!=''){
  1632. $code = explode(",",$bidinfos['origin_place']);
  1633. $temp=[];
  1634. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1635. $temp['city_code']=isset($code[1])?$code[1]:"";
  1636. $temp['area_code']=isset($code[2])?$code[2]:"";
  1637. $addr= GetAddr(json_encode($temp));
  1638. $info['origin_addr'] = $addr;
  1639. }
  1640. $info['supplierNo'] =$bidinfos['supplierNo'];
  1641. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1642. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1643. $info['pay_way'] =$bidinfos['pay_way'];
  1644. $info['tax'] =$bidinfos['tax'];
  1645. $info['send_way'] =$bidinfos['send_way'];
  1646. $info['metal_id'] =$bidinfos['metal_id'];
  1647. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1648. $info['config'] =$bidinfos['config'];
  1649. $info['other_config'] =$bidinfos['other_config'];
  1650. $info['weight'] =$bidinfos['weight'];
  1651. $info['good_weight'] =$bidinfos['good_weight'];
  1652. $info['is_diff'] =$bidinfos['is_diff'];
  1653. $info['demo_fee'] =$bidinfos['demo_fee'];
  1654. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1655. $info['open_fee'] =$bidinfos['open_fee'];
  1656. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1657. $info['nake_fee'] =$bidinfos['nake_fee'];
  1658. $info['mark_fee'] =$bidinfos['mark_fee'];
  1659. $info['cert_fee'] =$bidinfos['cert_fee'];
  1660. $info['cost_fee'] =$bidinfos['cost_fee'];
  1661. $info['total_fee'] =$bidinfos['total_fee'];
  1662. $info['supply_area'] =$bidinfos['supply_area'];
  1663. $info['remark'] =$bidinfos['remark'];
  1664. $info['is_addrs'] =$consultinfos['is_addrs'];
  1665. $info['is_custom'] =$consultinfos['is_custom'];
  1666. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1667. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1668. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1669. if($info['status']==7){
  1670. $info['lower_price'] =round($lower_price,2);
  1671. }
  1672. //获取议价原因
  1673. if ($info['result_info_id'] != 0) {
  1674. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1675. } else {
  1676. $info['result_info'] = '';
  1677. }
  1678. return app_show(0,"获取成功",$info);
  1679. }
  1680. public function bidlist(){
  1681. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1682. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1683. $where=[['is_del',"=",0]];
  1684. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1685. if ($zxNo !== "") {
  1686. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1687. }
  1688. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1689. if ($infoNo !== "") {
  1690. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1691. }
  1692. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1693. if ($bidNo !== "") {
  1694. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1695. }
  1696. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1697. if ($pgNo !== "") {
  1698. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1699. $where[] = ['infoNo','in',$bidinfo];
  1700. }
  1701. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1702. if ($bargain_status !== "") {
  1703. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1704. $where[] = ['infoNo','in',$bidinfo];
  1705. }
  1706. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1707. if ($projectNo !== "") {
  1708. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1709. ("zxNo");
  1710. $where[] = ['zxNo','in',$zxlist];
  1711. }
  1712. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1713. if($is_own==1){
  1714. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1715. if($token==""){
  1716. return error_show(101,'token不能为空');
  1717. }
  1718. $apply_id =GetUserInfo($token);
  1719. if(empty($apply_id)||$apply_id['code']!=0){
  1720. return error_show(1002,"申请人数据不存在");
  1721. }
  1722. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1723. $where[]=['createrid',"=",$rm];
  1724. }
  1725. $count = Db::name('consult_bids')->where($where)->count();
  1726. $total = ceil($count / $size);
  1727. $page = $page >= $total ? $total : $page;
  1728. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1729. $data=[];
  1730. foreach ($list as $value){
  1731. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1732. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1733. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1734. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1735. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1736. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1737. if($value['brand_id']!=0){
  1738. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1739. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1740. }else{
  1741. $value["brand_name"]="";
  1742. $value["brand_id"]="";
  1743. }
  1744. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1745. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1746. $god=[
  1747. "metal_id"=>$value['metal_id'],
  1748. "weight"=>$value["good_weight"],
  1749. "demo_fee"=>$value["demo_fee"],
  1750. "delivery_fee"=>$value["delivery_fee"],
  1751. "open_fee"=>$value["open_fee"],
  1752. "packing_fee"=>$value["pakge_fee"],
  1753. "mark_fee"=>$value["mark_fee"],
  1754. "nake_fee"=>$value["nake_fee"],
  1755. "cert_fee"=>$value["cert_fee"],
  1756. // "cost_fee"=>$value["cost_fee"],
  1757. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1758. //暂时注掉,搞不清楚原因@吴广广
  1759. "num"=>$bidinfo["num"],
  1760. ];
  1761. $top_cat = made($value['cat_id']);
  1762. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1763. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1764. $price = GoldPrice($god, $budget/100);
  1765. $value['sale_price'] = round($price,2);
  1766. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1767. $value["origin_price"];
  1768. }
  1769. $value['cost_fee'] =$value['origin_cost_fee'];
  1770. $value['specinfo'] = json_decode($value['specinfo'],true);
  1771. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1772. $value['bargain_status']=$bidinfo['bargain_status'];
  1773. //reject驳回原因,status==5表示驳回
  1774. $value['reject']=[];
  1775. if ($value['status'] >=5) {
  1776. $value['reject'] = Db::name('bargain_order')
  1777. ->field('id,remark,status')
  1778. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1779. ->whereIn('status', [3,8,11])->order("id desc")
  1780. ->find();
  1781. }
  1782. //产地
  1783. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1784. if($value['delivery_place']!=""){
  1785. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1786. }
  1787. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1788. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1789. if($value['origin_place']!=""){
  1790. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1791. }
  1792. $value['origin_addr']=GetAddr(json_encode($place));
  1793. // if($value['origin_place']!=''){
  1794. // $code = explode(",",$value['origin_place']);
  1795. // $temp=[];
  1796. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1797. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1798. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1799. // $addr= GetAddr(json_encode($temp));
  1800. // $value['origin_addr'] = $addr;
  1801. // }
  1802. $data[] = $value;
  1803. }
  1804. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1805. }
  1806. public function feedlist(){
  1807. $where=[['is_del',"=",0]];
  1808. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1809. if ($zxNo !== "") {
  1810. $where[] = ['zxNo','=',$zxNo];
  1811. }
  1812. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1813. if ($infoNo !== "") {
  1814. $where[] = ['infoNo','=',$infoNo];
  1815. }
  1816. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1817. if ($bidNo !== "") {
  1818. $where[] = ['bidNo','=',$bidNo];
  1819. }
  1820. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1821. if ($projectNo !== "") {
  1822. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1823. ("zxNo");
  1824. $where[] = ['zxNo','in',$zxlist];
  1825. }
  1826. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1827. if($token==''){
  1828. return error_show(102,"参数token不能为空");
  1829. }
  1830. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1831. if($is_own==1){
  1832. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1833. if($token==""){
  1834. return error_show(101,'token不能为空');
  1835. }
  1836. $apply_id =GetUserInfo($token);
  1837. if(empty($apply_id)||$apply_id['code']!=0){
  1838. return error_show(1002,"申请人数据不存在");
  1839. }
  1840. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1841. $where[]=['createrid',"=",$rm];
  1842. }
  1843. $list =Db::name('consult_bids')->where($where)->select();
  1844. $data=[];
  1845. foreach ($list as $value){
  1846. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1847. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1848. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1849. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1850. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1851. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1852. if($value['brand_id']!=0){
  1853. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1854. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1855. }else{
  1856. $value["brand_name"]="";
  1857. $value["brand_id"]="";
  1858. }
  1859. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1860. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1861. $god=[
  1862. "metal_id"=>$value['metal_id'],
  1863. "weight"=>$value["good_weight"],
  1864. "demo_fee"=>$value["demo_fee"],
  1865. "delivery_fee"=>$value["delivery_fee"],
  1866. "open_fee"=>$value["open_fee"],
  1867. "packing_fee"=>$value["pakge_fee"],
  1868. "mark_fee"=>$value["mark_fee"],
  1869. "nake_fee"=>$value["nake_fee"],
  1870. "cert_fee"=>$value["cert_fee"],
  1871. "cost_fee"=>$value["cost_fee"],
  1872. "num"=>$bidinfo["num"],
  1873. ];
  1874. if ($value['is_gold_price'] == 1 ) {
  1875. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1876. ->find();
  1877. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1878. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1879. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1880. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1881. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1882. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1883. }else{
  1884. if($value["nake_fee"]){
  1885. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1886. }else{
  1887. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1888. (1 - $budget);
  1889. }
  1890. }
  1891. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1892. $value['specinfo'] = json_decode($value['specinfo'],true);
  1893. $value['bargain_status']=$bidinfo['bargain_status'];
  1894. $data[]=$value;
  1895. }
  1896. return app_show(0,"获取成功",$data);
  1897. }
  1898. public function bragain_list(){
  1899. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1900. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1901. $where=[['bo.is_del',"=",0]];
  1902. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1903. if($bidsNo!=""){
  1904. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1905. }
  1906. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1907. if ($zxNo !== "") {
  1908. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1909. }
  1910. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1911. if ($bargainNo !== "") {
  1912. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1913. }
  1914. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1915. if ($status!== "") {
  1916. $where[] = ['bo.status','=',$status];
  1917. }
  1918. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1919. if ($infoNo !== "") {
  1920. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1921. }
  1922. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1923. if ($projectNo !== "") {
  1924. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1925. ("zxNo");
  1926. $where[] = ['bo.zxNo','in',$zxlist];
  1927. }
  1928. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1929. if ($pgNo !== "") {
  1930. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1931. $where[] = ['bo.infoNo','in',$bidinfo];
  1932. }
  1933. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1934. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1935. if($start!=""){
  1936. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1937. }
  1938. if($end!=""){
  1939. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1940. }
  1941. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1942. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1943. $role=$this->checkRole();
  1944. if(!empty($role['write'])){
  1945. $where[]=["bo.createrid","in",$role['write']];
  1946. }
  1947. $count=Db::name("bargain_order")->alias('bo')->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")->where($where)->count();
  1948. $total = ceil($count / $size);
  1949. $page = $page >= $total ? $total : $page;
  1950. $list = Db::name('bargain_order')
  1951. ->alias('bo')
  1952. ->field('bo.*,u.itemid')
  1953. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1954. ->where($where)
  1955. ->page($page, $size)
  1956. ->order('bo.addtime', 'desc')
  1957. ->cursor();
  1958. $data=[];
  1959. foreach ($list as $value){
  1960. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1961. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1962. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1963. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1964. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1965. if($bidinfos['brand_id']!=0){
  1966. $value['brand_id'] = $bidinfos['brand_id'];
  1967. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1968. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1969. }else{
  1970. $value["brand_name"]="";
  1971. $value["brand_id"]="";
  1972. }
  1973. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1974. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1975. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1976. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1977. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1978. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1979. $value['budget'] =$budget;
  1980. $god=[
  1981. "metal_id"=>$bidinfos['metal_id'],
  1982. "weight"=>$bidinfos["good_weight"],
  1983. "demo_fee"=>$bidinfos["demo_fee"],
  1984. "delivery_fee"=>$bidinfos["delivery_fee"],
  1985. "open_fee"=>$bidinfos["open_fee"],
  1986. "packing_fee"=>$bidinfos["pakge_fee"],
  1987. "mark_fee"=>$bidinfos["mark_fee"],
  1988. "nake_fee"=>$bidinfos["nake_fee"],
  1989. "cert_fee"=>$bidinfos["cert_fee"],
  1990. "cost_fee"=>$bidinfos["cost_fee"],
  1991. "num"=>$bidinfoe["num"],
  1992. ];
  1993. // if($bidinfos['is_gold_price']==1){
  1994. // $price = GoldPrice($god, $budget/100);
  1995. // }else{
  1996. // $price = GoodPrice($god, $budget/100);
  1997. // }
  1998. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1999. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2000. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2001. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2002. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2003. $data[]=$value;
  2004. }
  2005. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2006. }
  2007. public function crontablist(){
  2008. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2009. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2010. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2011. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2012. if ($zxNo !== "") {
  2013. $where[] = ['a.zxNo','=',$zxNo];
  2014. }
  2015. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2016. if ($salesman !== "") {
  2017. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2018. $where[]= ["b.salesman",'like',"%$salesman%"];
  2019. }
  2020. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2021. if ($cpName !== "") {
  2022. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2023. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2024. }
  2025. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2026. if ($khNo !== "") {
  2027. // $where['khNo'] = $khNo;
  2028. $where[]= ["b.khNo",'like',"%$khNo%"];
  2029. }
  2030. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2031. if ($start !="") {
  2032. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2033. $where[]= ["a.addtime",'>=',$start];
  2034. }
  2035. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2036. if($end !=""){
  2037. $where[]= ["a.addtime",'<=',$end];
  2038. }
  2039. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2040. if ($status !== "") {
  2041. $where[]= ["a.status",'=',$status];
  2042. }
  2043. // $role=$this->checkRole();
  2044. // if(!empty($role['platform']) ){
  2045. // $where[]=["b.platform_code","in",$role['platform']];
  2046. // }
  2047. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2048. ->count();
  2049. $total = ceil($count / $size);
  2050. $page = $page >= $total ? $total : $page;
  2051. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2052. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2053. $data=[];
  2054. foreach ($list as $value){
  2055. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2056. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2057. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2058. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2059. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2060. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2061. $value['khname']="";
  2062. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2063. true):[];
  2064. if($value['khNo']!==""){
  2065. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2066. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2067. }
  2068. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2069. ->find();
  2070. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2071. $value['is_feed'] =$consult==false?0:1;
  2072. $value['is_all_feed'] =$consults==false?0:1;
  2073. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2074. $data[]=$value;
  2075. }
  2076. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2077. }
  2078. //复制上面的bidlist方法,只更改排序方式
  2079. public function bidlistCopy()
  2080. {
  2081. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2082. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2083. $where = [['cb.is_del', "=", 0]];
  2084. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2085. if ($zxNo !== "") {
  2086. $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2087. }
  2088. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2089. if ($infoNo !== "") {
  2090. $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2091. }
  2092. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2093. if ($bidNo !== "") {
  2094. $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2095. }
  2096. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2097. if ($pgNo !== "") {
  2098. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2099. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2100. }
  2101. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2102. if ($bargain_status !== "") {
  2103. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2104. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2105. }
  2106. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2107. if ($projectNo !== "") {
  2108. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  2109. ("zxNo");
  2110. $where[] = ['cb.zxNo', 'in', $zxlist];
  2111. }
  2112. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2113. if ($is_own == 1) {
  2114. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2115. if ($token == "") {
  2116. return error_show(101, 'token不能为空');
  2117. }
  2118. $apply_id = GetUserInfo($token);
  2119. if (empty($apply_id) || $apply_id['code'] != 0) {
  2120. return error_show(1002, "申请人数据不存在");
  2121. }
  2122. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2123. $where[] = ['cb.createrid', "=", $rm];
  2124. }
  2125. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2126. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2127. $count = Db::name('consult_bids')->alias('cb')->where($where)->count();
  2128. $total = ceil($count / $size);
  2129. $page = $page >= $total ? $total : $page;
  2130. $list = Db::name('consult_bids')
  2131. ->alias('cb')
  2132. ->field('cb.*,u.itemid')
  2133. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2134. ->where($where)
  2135. ->page($page, $size)
  2136. ->order('cb.addtime', 'desc')
  2137. ->cursor();
  2138. $data = [];
  2139. foreach ($list as $value) {
  2140. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2141. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2142. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2143. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2144. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2145. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2146. if ($value['brand_id'] != 0) {
  2147. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2148. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2149. } else {
  2150. $value["brand_name"] = "";
  2151. $value["brand_id"] = "";
  2152. }
  2153. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2154. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2155. $god = [
  2156. "metal_id" => $value['metal_id'],
  2157. "weight" => $value["good_weight"],
  2158. "demo_fee" => $value["demo_fee"],
  2159. "delivery_fee" => $value["delivery_fee"],
  2160. "open_fee" => $value["open_fee"],
  2161. "packing_fee" => $value["pakge_fee"],
  2162. "mark_fee" => $value["mark_fee"],
  2163. "nake_fee" => $value["nake_fee"],
  2164. "cert_fee" => $value["cert_fee"],
  2165. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2166. "num" => $bidinfo["num"],
  2167. ];
  2168. if ($value['is_gold_price'] == 1) {
  2169. $price = GoldPrice($god, $budget / 100);
  2170. $value['sale_price'] = round($price, 2);
  2171. }
  2172. $value['cost_fee'] = $value['origin_cost_fee'];
  2173. $value['specinfo'] = json_decode($value['specinfo'], true);
  2174. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2175. $value['bargain_status'] = $bidinfo['bargain_status'];
  2176. //reject驳回原因,status==5表示驳回
  2177. $value['reject'] = [];
  2178. if ($value['status'] >= 5) {
  2179. $value['reject'] = Db::name('bargain_order')
  2180. ->field('id,remark,status')
  2181. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2182. ->whereIn('status', [3, 8, 11])->order("id desc")
  2183. ->find();
  2184. }
  2185. //产地
  2186. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2187. if ($value['delivery_place'] != "") {
  2188. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2189. }
  2190. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2191. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2192. if ($value['origin_place'] != "") {
  2193. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2194. }
  2195. $value['origin_addr'] = GetAddr(json_encode($place));
  2196. // if($value['origin_place']!=''){
  2197. // $code = explode(",",$value['origin_place']);
  2198. // $temp=[];
  2199. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2200. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2201. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2202. // $addr= GetAddr(json_encode($temp));
  2203. // $value['origin_addr'] = $addr;
  2204. // }
  2205. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2206. $data[] = $value;
  2207. }
  2208. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2209. }
  2210. }